Giter VIP home page Giter VIP logo

Comments (1)

kou avatar kou commented on May 28, 2024 1

Oh, this is difficult to fix...

WIP patch:

diff --git a/lib/ii.c b/lib/ii.c
index 75849fb7c..134525515 100644
--- a/lib/ii.c
+++ b/lib/ii.c
@@ -13533,19 +13533,25 @@ grn_ii_select_cursor_next_find_near(grn_ctx *ctx,
   bool need_check = true;
   if (data->mode == GRN_OP_NEAR_PHRASE ||
       data->mode == GRN_OP_ORDERED_NEAR_PHRASE) {
+    int32_t start_pos = data->pos;
     uint32_t phrase_id;
     for (phrase_id = 0; phrase_id < data->n_phrases; phrase_id++) {
-      if (!grn_ii_select_data_find_phrase(ctx, data, phrase_id, data->pos, 0)) {
+      if (!grn_ii_select_data_find_phrase(ctx, data, phrase_id, start_pos, 0)) {
         need_check = false;
         break;
       }
-      /* TODO: Can we update data->pos to reduce needless search? */
       bt_push(data->bt, data->token_info);
+      if (data->mode == GRN_OP_ORDERED_NEAR_PHRASE &&
+          data->token_info->pos > start_pos) {
+        start_pos = data->token_info->pos;
+      }
+      /* TODO: Can we update data->pos to reduce needless search? */
     }
   } else if (data->mode == GRN_OP_NEAR_PHRASE_PRODUCT ||
              data->mode == GRN_OP_ORDERED_NEAR_PHRASE_PRODUCT) {
     uint32_t i;
     uint32_t phrase_id = 0;
+    int32_t start_pos = data->pos;
     for (i = 0; i < data->n_phrase_groups; i++) {
       phrase_group *group = &(data->phrase_groups[i]);
       bt_zap(group->btree);
@@ -13555,10 +13561,14 @@ grn_ii_select_cursor_next_find_near(grn_ctx *ctx,
         if (grn_ii_select_data_find_phrase(ctx,
                                            data,
                                            phrase_id,
-                                           data->pos,
+                                           start_pos,
                                            0)) {
           have_phrase = true;
           bt_push(group->btree, data->token_info);
+          if (data->mode == GRN_OP_ORDERED_NEAR_PHRASE_PRODUCT &&
+              data->token_info->pos > start_pos) {
+            start_pos = data->token_info->pos;
+          }
           /* TODO: Can we update data->pos to reduce needless search? */
         }
       }
diff --git a/test/command/suite/select/query/ordered_near_phrase_product/same_phrases.test b/test/command/suite/select/query/ordered_near_phrase_product/same_phrases.test
new file mode 100644
index 000000000..2ecd7e858
--- /dev/null
+++ b/test/command/suite/select/query/ordered_near_phrase_product/same_phrases.test
@@ -0,0 +1,19 @@
+table_create Entries TABLE_NO_KEY
+column_create Entries content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenNgram \
+  --normalizer NormalizerNFKC150
+column_create Terms entries_content COLUMN_INDEX|WITH_POSITION Entries content
+
+load --table Entries
+[
+{"content": "a.b.c.d"},
+{"content": "a[.]b.c[.]d"},
+{"content": "x.y.z"}
+]
+
+select Entries \
+  --match_columns content \
+  --query '*ONPP10"(a) (. [.]) (b) (. [.]) (c) (. [.]) (d)"' \
+  --output_columns '_score, content'

from groonga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.