関口宏司のLuceneブログ

OSS検索ライブラリのLuceneおよびそのサブプロジェクト(Solr/Tika/Mahoutなど)について
<< Solr runs on Jailbroken iPad | main | (メモ)Solr負荷テストツール SolrMeter >>
スポンサーサイト

一定期間更新がないため広告を表示しています

| スポンサードリンク | - | | - | - |
デフォルトでPhraseQueryを生成しなくなったQueryParserに注意(3.1)
QueryParserは、クエリ文字列からQueryオブジェクトを生成するクラスだが、Analyzerが文字列を複数トークン返してくる際に、これまではPhraseQueryを生成していた。ところがLucene 3.1からはBooleanQueryのORに展開するように変更された:

https://issues.apache.org/jira/browse/LUCENE-2458

特にCJKAnalyzerなどのN-gram系Analyzerを使っている場合には単語(のつもり)が複数トークンを返すことが多いので、注意が必要である。以下にプログラムを示す:

public static void main(String[] args) throws Exception {
  final Version V = Version.LUCENE_31;
  QueryParser parser = new QueryParser( V, "F", new CJKAnalyzer( V ) );
  //System.out.println( "autoGeneratePhraseQueries = " + parser.getAutoGeneratePhraseQueries() );
  //parser.setAutoGeneratePhraseQueries( true );
  Query query = parser.parse( "こんにちは" );
  System.out.println( "query.toString() = " + query.toString() );
  System.out.println( "type of query = " + query.getClass().getSimpleName() );
}


実行結果は次のようになる:

query.toString() = F:こん F:んに F:にち F:ちは
type of query = BooleanQuery


プログラムのバージョンをLUCENE_30(以前)にしたり、コメントアウト部分を有効にすると、実行結果は次の通りとなり、これまでのようにPhraseQueryが生成されるのがわかる:

query.toString() = F:"こん んに にち ちは"
type of query = PhraseQuery
| 関口宏司 | Luceneクラス解説 | 11:10 | comments(1) | trackbacks(1) |
スポンサーサイト
| スポンサードリンク | - | 11:10 | - | - |
メモ:

this is in reference to Tom's comment on his "l'art" problem (
http://www.hathitrust.org/blogs/large-scale-search/tuning-search-performance
).

so, there are two problems:
1. that the queryparser "pre-tokenizes" on whitespace at all.
2. that the queryparser forms a phrase query, if the analyzer returns more
than one position back from a "queryparser token" (whitespace).

turning off autoGeneratePhraseQueries only solves problem #2, because its
not appropriate for many languages. Before this option (e.g. Solr 1.4.x),
you had to use the PositionFilter to workaround this problem. But
PositionFilter simply "flattens/stacks" the positions (makes it seem as if
they are all synonyms). With PositionFilter you couldn't have phrase queries
at all... and you don't get a BooleanQuery coordination factor.

with autoGeneratePhraseQueries=false, you won't get a phrase query unless it
was in double quotes... its just that simple.

fixing problem #1 alltogether, is the way to go. Because then the
tokenization would be left to the analyzer completely, and you would have a
lot more flexibility: https://issues.apache.org/jira/browse/LUCENE-2605

| 関口 | 2010/09/26 12:10 AM |









トラックバック機能は終了しました。
[lucene]Lucene3.1でのQueryParserの挙動変更
デフォルトでPhraseQueryを生成しなくなったQueryParserに注意(3.1)を読んで意味が分からなかったので、プログラムを実行してみた public class TestLucene2458 { static final Version V = Version.LUCENE_31; public static void main(String args[]) throws Corru
| FrontRunner | 2010/07/30 7:05 AM |
+ Solrによるブログ内検索
+ PROFILE
     12
3456789
10111213141516
17181920212223
24252627282930
31      
<< March 2024 >>
+ LINKS
検索エンジン製品 - 比較のポイント
商用検索エンジンを購入した企業担当者は読まないでください。ショックを受けますから・・・
>>製品比較 10のポイント
+ Lucene&Solrデモ
+ ThinkIT記事
+ RECOMMEND
Apache Solr入門 ―オープンソース全文検索エンジン
Apache Solr入門 ―オープンソース全文検索エンジン (JUGEMレビュー »)
関口 宏司,三部 靖夫,武田 光平,中野 猛,大谷 純
+ RECOMMEND
Lucene in Action
Lucene in Action (JUGEMレビュー »)
Erik Hatcher,Otis Gospodnetic,Mike McCandless
FastVectorHighlighterについて解説記事を寄稿しました。
+ RECOMMEND
+ SELECTED ENTRIES
+ RECENT COMMENTS
+ RECENT TRACKBACK
+ CATEGORIES
+ ARCHIVES
+ MOBILE
qrcode
+ SPONSORED LINKS