airborne12 commented on code in PR #36356:
URL: https://github.com/apache/doris/pull/36356#discussion_r1670527975


##########
be/src/olap/rowset/segment_v2/inverted_index/query/phrase_query.cpp:
##########
@@ -21,9 +21,105 @@
 
 namespace doris::segment_v2 {
 
+template <typename Derived>
+bool PhraseMatcherBase<Derived>::matches(int32_t doc) {
+    reset(doc);
+    return static_cast<Derived*>(this)->next_match();
+}
+
+template <typename Derived>
+void PhraseMatcherBase<Derived>::reset(int32_t doc) {
+    for (PostingsAndPosition& posting : _postings) {
+        if (posting._postings.docID() != doc) {
+            posting._postings.advance(doc);
+        }
+        posting._freq = posting._postings.freq();
+        posting._pos = -1;
+        posting._upTo = 0;
+    }
+}
+
+template <typename Derived>
+bool PhraseMatcherBase<Derived>::advance_position(PostingsAndPosition& 
posting, int32_t target) {
+    while (posting._pos < target) {
+        if (posting._upTo == posting._freq) {
+            return false;
+        } else {
+            posting._pos = posting._postings.nextPosition();
+            posting._upTo += 1;
+        }
+    }
+    return true;
+}
+
+bool ExactPhraseMatcher::next_match() {
+    PostingsAndPosition& lead = _postings[0];
+    if (lead._upTo < lead._freq) {
+        lead._pos = lead._postings.nextPosition();
+        lead._upTo += 1;
+    } else {
+        return false;
+    }
+
+    while (true) {
+        int32_t phrasePos = lead._pos - lead._offset;
+
+        bool advance_head = false;
+        for (size_t j = 1; j < _postings.size(); ++j) {
+            PostingsAndPosition& posting = _postings[j];
+            int32_t expectedPos = phrasePos + posting._offset;
+            // advance up to the same position as the lead
+            if (!advance_position(posting, expectedPos)) {
+                return false;
+            }
+
+            if (posting._pos != expectedPos) { // we advanced too far
+                if (advance_position(lead, posting._pos - posting._offset + 
lead._offset)) {
+                    advance_head = true;
+                    break;
+                } else {
+                    return false;
+                }
+            }
+        }
+        if (advance_head) {
+            continue;
+        }
+
+        return true;
+    }
+
+    return false;
+}
+
+bool OrderedSloppyPhraseMatcher::next_match() {
+    PostingsAndPosition* prev_posting = _postings.data();
+    while (prev_posting->_upTo < prev_posting->_freq) {
+        prev_posting->_pos = prev_posting->_postings.nextPosition();
+        prev_posting->_upTo += 1;
+        if (stretchToOrder(prev_posting) && _match_width <= _allowed_slop) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool OrderedSloppyPhraseMatcher::stretchToOrder(PostingsAndPosition* 
prev_posting) {

Review Comment:
   use consistent function name style here.
   may be stretch_to_order is better



-- 
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...@doris.apache.org

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


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

Reply via email to