[Groonga-commit] groonga/gcs [master] bq: support query expansion in phrase

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Aug 14 18:46:23 JST 2012


Kouhei Sutou	2012-08-14 18:46:23 +0900 (Tue, 14 Aug 2012)

  New Revision: 71ff98e6b1a7dd2a5f56044603cab2fa9cbec198
  https://github.com/groonga/gcs/commit/71ff98e6b1a7dd2a5f56044603cab2fa9cbec198

  Log:
    bq: support query expansion in phrase

  Modified files:
    lib/bq-translator.js
    test/bq-translator.test.js

  Modified: lib/bq-translator.js (+9 -1)
===================================================================
--- lib/bq-translator.js    2012-08-14 18:35:39 +0900 (fb0c9cf)
+++ lib/bq-translator.js    2012-08-14 18:46:23 +0900 (d8f92cc)
@@ -296,7 +296,15 @@ BooleanQueryTranslator.prototype = {
         value += character;
       } else if (character == "\"") {
         this.offset++;
-        return this.constructBinaryOperation(field, "@", "\"" + value + "\"");
+        var expandedPhrases = this.expandWord(value);
+        var expressions = expandedPhrases.map(function(phrase) {
+          return this.constructBinaryOperation(field, "@", "\"" + phrase + "\"");
+        }, this);
+        if (expressions.length >= 2) {
+          return "(" + expressions.join(" || ") + ")";
+        } else {
+          return expressions[0];
+        }
       } else {
         value += character;
       }

  Modified: test/bq-translator.test.js (+21 -4)
===================================================================
--- test/bq-translator.test.js    2012-08-14 18:35:39 +0900 (b72632a)
+++ test/bq-translator.test.js    2012-08-14 18:46:23 +0900 (806671a)
@@ -350,20 +350,37 @@ suite('BoolanQueryTranslator', function() {
                              "'ModelName'||",
                              "no default field");
 
-  testSynonym("existent: 0 synonym",
+  testSynonym("keyword: existent: 0 synonym",
               "'tokio'",
               { tokio: [] },
               '');
-  testSynonym("existent: 1 synonym",
+  testSynonym("keyword: existent: 1 synonym",
               "'tokio'",
               { tokio: ["tokyo"] },
               'field @ "tokyo"');
-  testSynonym("existent: N synonyms",
+  testSynonym("keyword: existent: N synonyms",
               "'tokio'",
               { tokio: ["tokio", "tokyo"] },
               '(field @ "tokio" || field @ "tokyo")');
-  testSynonym("nonexistent",
+  testSynonym("keyword: nonexistent",
               "'hokkaido'",
               { tokio: ["tokio", "tokyo"] },
               'field @ "hokkaido"');
+
+  testSynonym("phrase: existent: 0 synonym",
+              "'\"tokyo disney land\"'",
+              { "tokyo disney land": [] },
+              '');
+  testSynonym("phrase: existent: 1 synonym",
+              "'\"tokyo disney land\"'",
+              { "tokyo disney land": ["TDL"] },
+              'field @ "TDL"');
+  testSynonym("phrase: existent: N synonyms",
+              "'\"tokyo disney land\"'",
+              { "tokyo disney land": ["tokyo disney land", "TDL"] },
+              '(field @ "tokyo disney land" || field @ "TDL")');
+  testSynonym("phrase: nonexistent",
+              "'\"tokyo disney land\"'",
+              { tokio: ["tokio", "tokyo"] },
+              'field @ "tokyo disney land"');
 });
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index