【发布时间】:2017-01-11 22:45:39
【问题描述】:
我正在对 Lucene 索引进行一些查询,现在我正在寻找针对此查询的拉丁短语。问题是其中一些短语包含我认为像塞子一样的词。例如,如果我的搜索词是“a contrario sensu”,结果为零,但如果我只搜索“contrario sensu”,我有 100 多个巧合。
问题是如果没有这个塞子我怎么能进行搜索?
我的代码是这样的
public IEnumerable<TesisIndx> Search(string searchTerm)
{
List<TesisIndx> results = new List<TesisIndx>();
IndexSearcher searcher = new IndexSearcher(FSDirectory.GetDirectory(indexPath));
QueryParser parser = new QueryParser("Rubro", analyzer);
PhraseQuery q = new PhraseQuery();
String[] words = searchTerm.Split(' ');
foreach (string word in words)
{
q.Add(new Term("Rubro", word));
}
//Query query = parser.Parse(searchTerm);
Hits hitsFound = searcher.Search(q);
TesisIndx sampleDataFileRow = null;
for (int i = 0; i < hitsFound.Length(); i++)
{
sampleDataFileRow = new TesisIndx();
Document doc = hitsFound.Doc(i);
sampleDataFileRow.Ius = int.Parse(doc.Get("Ius"));
sampleDataFileRow.Rubro = doc.Get("Rubro");
sampleDataFileRow.Texto = doc.Get("Texto");
results.Add(sampleDataFileRow);
}
}
我使用 StandardAnalyzer 构建索引并执行搜索
【问题讨论】:
标签: search lucene lucene.net