[groonga-dev,02859] Re: BOOLEAN MODEの+とか-の意味

Back to archive index

Kouhei Sutou kou****@clear*****
2014年 10月 24日 (金) 12:43:58 JST


須藤です。

In <20141****@clear*****>
  "[groonga-dev,02857] Re: BOOLEAN MODEの+とか-の意味" on Fri, 24 Oct 2014 12:30:24 +0900 (JST),
  Kouhei Sutou <kou****@clear*****> wrote:

> http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html
> 
> の前置なしのキーワードのところの説明は↓となっているので、OR
> というよりも、「検索結果に影響なくスコアを変えるだけ」みたい
> に扱ったほうがいいんですかねぇ。
> 
>> (no operator)
>>
>> By default (when neither + nor - is specified), the word is
>> optional, but the rows that contain it are rated
>> higher. This mimics the behavior of MATCH() ... AGAINST()
>> without the IN BOOLEAN MODE modifier.

このパッチを当てた時の挙動はどう思いますか?

--
diff --git a/ha_mroonga.cpp b/ha_mroonga.cpp
index dd9967d..c105a62 100644
--- a/ha_mroonga.cpp
+++ b/ha_mroonga.cpp
@@ -7678,7 +7678,7 @@ grn_rc ha_mroonga::generic_ft_init_ext_prepare_expression_in_boolean_mode(
 
   const char *keyword, *keyword_original;
   uint keyword_length, keyword_length_original;
-  grn_operator default_operator = GRN_OP_OR;
+  grn_operator default_operator = GRN_OP_ADJUST;
   grn_bool weight_specified = false;
   keyword = keyword_original = key->ptr();
   keyword_length = keyword_length_original = key->length();
--

手元だとこんな感じになりました。

SET NAMES utf8;
DROP TABLE IF EXISTS books;

CREATE TABLE books (
  `id` INTEGER AUTO_INCREMENT,
  `title` text,
  PRIMARY KEY(`id`),
  FULLTEXT INDEX title_index (title)
) ENGINE=mroonga default charset utf8;

INSERT INTO books (title) VALUES ('Quick brown fox jumps over the lazy dog.');
INSERT INTO books (title) VALUES ('Slow white fox jumps over the diligent dog.');

SELECT title, MATCH (title) AGAINST('+quick fox dog' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	3
-- Slow white fox jumps over the diligent dog.	0

SELECT title, MATCH (title) AGAINST('fox +quick dog' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	3
-- Slow white fox jumps over the diligent dog.	0

SELECT title, MATCH (title) AGAINST('fox dog +quick' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	3
-- Slow white fox jumps over the diligent dog.	0

SELECT title, MATCH (title) AGAINST('fox dog -quick' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	0
-- Slow white fox jumps over the diligent dog.	2

SELECT title, MATCH (title) AGAINST('fox -quick dog' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	0
-- Slow white fox jumps over the diligent dog.	2

SELECT title, MATCH (title) AGAINST('-quick fox dog' IN BOOLEAN MODE) AS score FROM books;
-- title	score
-- Quick brown fox jumps over the lazy dog.	0
-- Slow white fox jumps over the diligent dog.	3

DROP TABLE books;


-- 
須藤 功平 <kou****@clear*****>
株式会社クリアコード <http://www.clear-code.com/>

Groongaベースの全文検索システムを総合サポート:
  http://groonga.org/ja/support/
パッチ採用 - プログラミングが楽しい人向けの採用プロセス:
  http://www.clear-code.com/recruitment/
コードリーダー育成支援 - 自然とリーダブルコードを書くチームへ:
  http://www.clear-code.com/services/code-reader/




groonga-dev メーリングリストの案内
Back to archive index