@@ -404,12 +404,10 @@ private static IReadOnlyList<ComponentWeight> ExtractComponentWeights(HybridSear
404404 for ( int index = 0 ; index < hybridSearchQueryInfo . ComponentQueryInfos . Count ; ++ index )
405405 {
406406 QueryInfo queryInfo = hybridSearchQueryInfo . ComponentQueryInfos [ index ] ;
407- Debug . Assert ( queryInfo . HasOrderBy , "The component query should have an order by" ) ;
408- Debug . Assert ( queryInfo . HasNonStreamingOrderBy , "The component query is a non streaming order by" ) ;
409- Debug . Assert ( queryInfo . OrderBy . Count == 1 , "The component query should have exactly one order by expression" ) ;
407+ SortOrder sortOrder = queryInfo . HasOrderBy ? queryInfo . OrderBy [ 0 ] : SortOrder . Descending ;
410408
411409 double componentWeight = useDefaultComponentWeight ? 1.0 : hybridSearchQueryInfo . ComponentWeights [ index ] ;
412- result . Add ( new ComponentWeight ( componentWeight , queryInfo . OrderBy [ 0 ] ) ) ;
410+ result . Add ( new ComponentWeight ( componentWeight , sortOrder ) ) ;
413411 }
414412
415413 return result ;
@@ -635,14 +633,19 @@ private static void ComputeRrfScores(
635633
636634 private static QueryInfo RewriteOrderByQueryInfo ( QueryInfo queryInfo , GlobalFullTextSearchStatistics statistics , int componentCount )
637635 {
638- Debug . Assert ( queryInfo . HasOrderBy , "The component query should have an order by" ) ;
639- Debug . Assert ( queryInfo . HasNonStreamingOrderBy , "The component query is a non streaming order by" ) ;
636+ IReadOnlyList < string > rewrittenOrderByExpressions = queryInfo . OrderByExpressions ;
640637
641- List < string > rewrittenOrderByExpressions = new List < string > ( queryInfo . OrderByExpressions . Count ) ;
642- foreach ( string orderByExpression in queryInfo . OrderByExpressions )
638+ if ( queryInfo . HasOrderBy )
643639 {
644- string rewrittenOrderByExpression = FormatComponentQueryTextWorkaround ( orderByExpression , statistics , componentCount ) ;
645- rewrittenOrderByExpressions . Add ( rewrittenOrderByExpression ) ;
640+ Debug . Assert ( queryInfo . HasNonStreamingOrderBy , "The component query is a non streaming order by" ) ;
641+ List < string > orderByExpressions = new List < string > ( queryInfo . OrderByExpressions . Count ) ;
642+ foreach ( string orderByExpression in queryInfo . OrderByExpressions )
643+ {
644+ string rewrittenOrderByExpression = FormatComponentQueryTextWorkaround ( orderByExpression , statistics , componentCount ) ;
645+ orderByExpressions . Add ( rewrittenOrderByExpression ) ;
646+ }
647+
648+ rewrittenOrderByExpressions = orderByExpressions ;
646649 }
647650
648651 string rewrittenQuery = FormatComponentQueryTextWorkaround ( queryInfo . RewrittenQuery , statistics , componentCount ) ;
@@ -777,18 +780,15 @@ private static string FormatComponentQueryTextWorkaround(string format, GlobalFu
777780
778781 private class ComponentWeight
779782 {
780- public SortOrder SortOrder { get ; }
781-
782783 public double Weight { get ; }
783784
784785 public Comparison < double > Comparison { get ; }
785786
786787 public ComponentWeight ( double weight , SortOrder sortOrder )
787788 {
788789 this . Weight = weight ;
789- this . SortOrder = sortOrder ;
790790
791- int comparisonFactor = ( this . SortOrder == SortOrder . Ascending ) ? 1 : - 1 ;
791+ int comparisonFactor = ( sortOrder == SortOrder . Ascending ) ? 1 : - 1 ;
792792 this . Comparison = ( x , y ) => comparisonFactor * x . CompareTo ( y ) ;
793793 }
794794 }
0 commit comments