0
環境:Lucene.Net搜索像A071,A072,A073
Lucene.Net 3.03
Visual Studio 2010中
我一直停留在這個問題上幾個小時,在這一點上我無法弄清楚問題所在。
我建一些指數命名爲 「專賣店」,像下面的格式,
A075,A073,A021 ....
每個字符串表示店鋪的ID,並通過 「」 分隔,
我想搜索「A073」,它將返回匹配的數據,如果「商店」包括提前「A073」
感謝
static RAMDirectory dir = new RAMDirectory();
public void BuildIndex()
{
IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.Add(new Field("PROD_ID", "", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Stores", "", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
for (int i = 1; i <= 10; i++)
{
doc.GetField("PROD_ID").SetValue(Guid.NewGuid().ToString());
doc.GetField("Stores").SetValue("a075,a073,no2" + i.ToString());
iw.AddDocument(doc);
}
iw.Optimize();
iw.Commit();
iw.Close();
}
private void Search(string KeyWord)
{
IndexSearcher search = new IndexSearcher(dir, true);
QueryParser qp = new QueryParser(Version.LUCENE_30, "Stores", new StandardAnalyzer(Version.LUCENE_30));
Query query = qp.Parse(KeyWord);
var hits = search.Search(query, null, search.MaxDoc).ScoreDocs;
foreach (var res in hits)
{
Response.Write(string.Format("PROD_ID:{0}/Stores{1}"
, search.Doc(res.Doc).Get("PROD_ID").ToString()
, search.Doc(res.Doc).Get("Stores").ToString() + "<BR>"));
}
}
嗨,Ela,我知道我可以使用通配符,如「*」,但有沒有其他方法來解決它〜謝謝 – holmes2136
@Holmes看到上次編輯,使用多值字段應該爲你做 – MichaC
嗨,Ela,你的意思是使用MultifieldQueryFieldParser?但它似乎像在多領域的搜索。你能給我一些樣本〜thx! – holmes2136