Copilot commented on code in PR #16118:
URL: https://github.com/apache/pinot/pull/16118#discussion_r2150463626


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/LuceneTextIndexUtils.java:
##########
@@ -33,27 +35,55 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class LuceneTextIndexUtils {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(LuceneTextIndexUtils.class);
 
   private LuceneTextIndexUtils() {
   }
 
   /**
+   * Converts a BooleanQuery to appropriate SpanQuery based on its clauses.
+   * For AND operations, uses SpanNearQuery with specified slop.
+   * For OR operations, uses SpanOrQuery.
+   * For NOT operations, uses SpanNotQuery.
    *
    * @param query a Lucene query
-   * @return a span query with 0 slop and the original clause order if the 
input query is boolean query with one or more
+   * @return a span query if the input query is boolean query with one or more
    * prefix or wildcard subqueries; the same query otherwise.
    */
   public static Query convertToMultiTermSpanQuery(Query query) {
     if (!(query instanceof BooleanQuery)) {
       return query;
     }
     LOGGER.debug("Perform rewriting for the phrase query {}.", query);
+
+    BooleanQuery booleanQuery = (BooleanQuery) query;
     ArrayList<SpanQuery> spanQueryLst = new ArrayList<>();
     boolean prefixOrSuffixQueryFound = false;
-    for (BooleanClause clause : ((BooleanQuery) query).clauses()) {
+    boolean isOrQuery = false;
+    boolean hasNotClause = false;
+    SpanQuery notQuery = null;
+
+    // First pass: Check query type and collect NOT clauses
+    for (BooleanClause clause : booleanQuery.clauses()) {
+      if (clause.getOccur() == BooleanClause.Occur.SHOULD) {
+        isOrQuery = true;

Review Comment:
   Mixed MUST and SHOULD clauses are currently classified as OR; consider 
explicitly handling mixed occurrences or documenting the fallback behavior.
   ```suggestion
           isOrQuery = true;
         } else if (clause.getOccur() == BooleanClause.Occur.MUST) {
           // Explicitly track the presence of MUST clauses
           isOrQuery = false; // Reset OR flag if MUST clause is found
   ```



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/text/LuceneTextIndexReader.java:
##########
@@ -169,8 +169,7 @@ public MutableRoaringBitmap getDocIds(String searchQuery) {
       QueryParserBase parser = 
_queryParserClassConstructor.newInstance(_column, _analyzer);
       // Phrase search with prefix/suffix matching may have leading *. E.g., 
`*pache pinot` which can be stripped by
       // the query parser. To support the feature, we need to explicitly set 
the config to be true.
-      if 
(_queryParserClass.equals("org.apache.lucene.queryparser.classic.QueryParser")
-              && _enablePrefixSuffixMatchingInPhraseQueries) {
+      if (_enablePrefixSuffixMatchingInPhraseQueries) {

Review Comment:
   Instead of string comparisons on parser class names, use 'instanceof 
QueryParser' (or the specific parser type) for clearer and safer type checks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to