Lucene 中搜索结果的相关性
我想要的是:
在搜索方法中,我将添加一个额外的参数,即 float 类型的相关性参数来设置截止相关性。假设如果截止值为 60%,我想要相关性高于 60% 的项目。
这是当前的搜索代码:
假设搜索文本是 在 lucene 文件系统中我有以下描述: 1)abcdef 2)ABC 3)abcd
现在它将获取上述所有三个文档,我想获取那些相关性高于 60% 的文档。
//现在我没有在方法中的任何地方使用相关性参数:
public static string[] Search(string searchText,float relevanceparam)
{
//List of ID
List<string> searchResultID = new List<string>();
IndexSearcher searcher = new IndexSearcher(reader);
Term searchTerm = new Term("Text", searchText);
Query query = new TermQuery(searchTerm);
Hits hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
float r = hits.Score(i);
Document doc = hits.Doc(i);
searchResultID.Add(doc.Get("ID"));
}
return searchResultID.ToArray();
}
编辑:
如果我为查询设置增强会怎样 说:query.SetBoost(1.6);--这相当于 60% 吗?
What I want is :
In the search method i will add an extra parameter say relevance param of type float to setup the cuttoff relevance. So lets say if the cutoff is 60% I want items that are higher than 60% relevance.
Here is current code of search :
say the search text is a
and in lucene file system i have following description:
1) abcdef
2)abc
3)abcd
for now it will fetch all the above three docuements , i want to fetch those which are that are higher than 60% relevance.
//for now i am not using the relevanceparam anywhere in the method :
public static string[] Search(string searchText,float relevanceparam)
{
//List of ID
List<string> searchResultID = new List<string>();
IndexSearcher searcher = new IndexSearcher(reader);
Term searchTerm = new Term("Text", searchText);
Query query = new TermQuery(searchTerm);
Hits hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
float r = hits.Score(i);
Document doc = hits.Doc(i);
searchResultID.Add(doc.Get("ID"));
}
return searchResultID.ToArray();
}
Edit :
what if i set boost to my query
say : query.SetBoost(1.6);-- is this is equivalent to 60 percent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过忽略那些小于
TopDocs.MaxScore * minRelativeRelevance
的点击轻松完成此操作,其中minRelativeRelevance
应该是 0 到 1 之间的值。我已经修改了您的代码为了匹配 Lucene.Net 3.0.3 版本,并在对
IndexSearcher.Doc
的调用中添加了 FieldSelector 以避免加载非必填字段。调用
Query.SetBoost(1.6)
仅意味着该查询计算出的分数将提高 60%(乘以 1.6)。如果涉及其他查询(例如,在 BooleanQuery 中),它可能会更改结果的顺序,但不会更改返回的结果。You can easily do this by ignore those hits that have less than a
TopDocs.MaxScore * minRelativeRelevance
whereminRelativeRelevance
should be a value between 0 and 1.I've modified your code to match the 3.0.3 release of Lucene.Net, and added a FieldSelector to your call to
IndexSearcher.Doc
to avoid loading non-required fields.Calling
Query.SetBoost(1.6)
would only mean that the score calculated by that query would be boosted by 60% (multiplied with 1.6). It may change the ordering of the result if there were other queries involved (in a BooleanQuery, for example), but it wont change which results are returned.