0
我已经看到过几个类似的问题,但我仍然没有答案。我想我有一个简单的问题。使用Lucene.Net精确查找
在句子
在本文中,只有元文件很重要,测试生成。 其他任何东西都是不相关的
我想索引仅元文件和测试代。这意味着我需要完全匹配。 有人可以请解释我如何做到这一点?
这里是代码:
Analyzer analyzer = new StandardAnalyzer();
Lucene.Net.Store.Directory directory = new RAMDirectory();
indexWriter iwriter = new IndexWriter(directory, analyzer, true);
iwriter.SetMaxFieldLength(10000);
Document doc = new Document();
doc.Add(new Field("textFragment", text, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
iwriter.AddDocument(doc);
iwriter.Close();
IndexSearcher isearcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser("textFragment", analyzer);
foreach (DictionaryEntry de in OntologyLayer.OntologyLayer.HashTable)
{
List<string> buffer = new List<string>();
double weight = 0;
List<OntologyLayer.Term> list = (List<OntologyLayer.Term>)de.Value;
foreach (OntologyLayer.Term t in list)
{
Hits hits = null;
string label = t.Label;
string[] words = label.Split(' ');
int numOfWords = words.Length;
double wordWeight = 1/(double)numOfWords;
double localWeight = 0;
foreach (string a in words)
{
try
{
if (!buffer.Contains(a))
{
Lucene.Net.Search.Query query = parser.Parse(a);
hits = isearcher.Search(query);
if (hits != null && hits.Length() > 0)
{
localWeight = localWeight + t.Weight * wordWeight * hits.Length();
}
buffer.Add(a);
}
}
catch (Exception ex)
{}
}
weight = weight + localWeight;
}
sbWeight.AppendLine(weight.ToString());
if (weight > 0)
{
string objectURI = (string)de.Key;
conceptList.Add(objectURI);
}
}
您应该提供输入示例并匹配给定的查询和结果。 – fyr
好的...我有一个概念本体论。我阅读每一个共同点,并尝试在文本中找到它。在这种情况下,它应该只返回元文件和测试生成,但我得到:随机数生成, 测试生成, 文本处理, 语言生成, 文档和文本编辑, 直线和曲线生成, 机器无关微码生成, 计划执行,形成和产生, 指数代, 元文件, 文件, 文本分析, 画像生成, 大文本档案, 文档和文本处理 – Srecko