2017.12.15 Friday
スポンサーサイト
一定期間更新がないため広告を表示しています
| スポンサードリンク | - | | - | - |
関口宏司のLuceneブログOSS検索ライブラリのLuceneおよびそのサブプロジェクト(Solr/Tika/Mahoutなど)について
2010.07.26 Monday
デフォルトで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 コメント
メモ:
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 |
コメントする
この記事のトラックバックURL
トラックバック機能は終了しました。
トラックバック
デフォルトで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
+ LINKS
+ Lucene&Solrデモ
+ ThinkIT記事
+ RECOMMEND
+ RECOMMEND
Lucene in Action (JUGEMレビュー »)
Erik Hatcher,Otis Gospodnetic,Mike McCandless FastVectorHighlighterについて解説記事を寄稿しました。
+ RECOMMEND
+ SELECTED ENTRIES
+ RECENT COMMENTS
+ RECENT TRACKBACK
+ CATEGORIES
+ ARCHIVES
+ MOBILE
+ SPONSORED LINKS
|
(C) 2024 ブログ JUGEM Some Rights Reserved.
|
PAGE TOP |