簡體   English   中英

Lucene .NET搜索

[英]Lucene .NET searching

嗨,我正在嘗試使用Lucene庫制作自動完成系統來搜索170K記錄。

但是有一個小問題。

例如,當我搜索Candice Gra(...)時,它會帶來諸如

Candice Jackson
Candice Hamilton
Candice Hayes

Bu not Candice Graham要讓Lucene找到Candice Graham我需要完全輸入Candice Graham

這是我正在建立查詢的代碼。

Directory directory = FSDirectory.Open(new DirectoryInfo(context.Server.MapPath("
ISet<string> stopWordSet = new HashSet<string>(stopWords);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWordSet);

IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);

//Singe Field Search
var queryParser = new QueryParser(Version.LUCENE_30,
                        "Title",
                        analyzer);
string strQuery = string.Format("{0}", q);
var query = queryParser.Parse(strQuery);

如果我這樣構建strQuery(*附加到查詢中)

string strQuery = string.Format("{0}*", q);

但是使用這種方式也會帶來不相關的記錄。 例如,如果我再次搜索Candice Gra(...),它將返回類似

Grass
Gravity
Gray (etc.)

順便說一句,我使用了KeywordAnalyzer和SimpleAnalyzer,但它們都不起作用。 有任何想法嗎?

如果要在搜索中包含空格,則應轉義它們;

var query = queryParser.Parse(QueryParser.Escape(strQuery));

我認為您需要在這兩個詞之間加入AND關鍵字。

“ Candice”和“ Gra”

http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#AND

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM