Browse Source

fixed a crash on using knn_dist() without a knn() query

Ilya Kuznetsov 2 years ago
parent
commit
a68636474a
3 changed files with 10 additions and 1 deletions
  1. 8 0
      src/sphinxsort.cpp
  2. 1 1
      test/test_275/model.bin
  3. 1 0
      test/test_275/test.xml

+ 8 - 0
src/sphinxsort.cpp

@@ -1628,6 +1628,11 @@ static bool IsGroupby ( const CSphString & s )
 		|| IsSortJsonInternal(s);
 }
 
+static bool IsKnnDist ( const CSphString & sExpr )
+{
+	return sExpr==GetKnnDistAttrName() || sExpr=="knn_dist()";
+}
+
 bool IsGroupbyMagic ( const CSphString & s )
 {
 	return IsGroupby ( s ) || IsCount ( s );
@@ -5225,6 +5230,9 @@ bool QueueCreator_c::ParseQueryItem ( const CSphQueryItem & tItem )
 		return true;
 	}
 
+	if ( IsKnnDist(sExpr) && m_pSorterSchema->GetAttrIndex ( GetKnnDistAttrName() )<0 )
+		return Err ( "KNN_DIST() is only allowed for KNN() queries" );
+
 	// not an attribute? must be an expression, and must be aliased by query parser
 	assert ( !tItem.m_sAlias.IsEmpty() );
 

File diff suppressed because it is too large
+ 1 - 1
test/test_275/model.bin


+ 1 - 0
test/test_275/test.xml

@@ -52,6 +52,7 @@ searchd
 	select * from t;
 	flush ramchunk t;
 	select * from t;
+	select id, knn_dist() from t;
 	drop table t;
 </sphinxql>
 </queries>

Some files were not shown because too many files changed in this diff