我在Lucene上实现了潜在的语义分析
算法的结果是由2列组成的矩阵,其中第一列是文档的索引,第二列是相似度。
我想在org.apache.lucene.search.Collector中写入对Searcher的方法搜索的响应,但是我不知道如何在收集器对象中设置结果。
搜索方法的代码是:
public void search(Weight weight, Filter filter, Collector collector) throws IOException
{
String textQuery = weight.getQuery().toString("contents");
System.out.println(textQuery);
double[][] ind;
ind = lsa.searchOnDoc(textQuery);
//ind contains the index and the similarity
if (ind != null)
{
//construct the collector object
for (int i=0; i<ind.length; i++)
{
int doc =(int) ind[i][0];
double simi = ind[i][1]
//collector.collect(doc);
//collector.setScorer(sim]);
//This is the problem
}
}
else
{
collector = null;
}
}我不知道复制收集器对象中ind值的正确步骤。
你能帮帮我吗?
发布于 2011-04-01 09:59:13
我不太明白你为什么决定把LSI推入Searcher。
从Weight获取文本查询看起来特别模糊--为什么不使用原始查询并跳过所有(中断的)转换?
但是Collector的处理方式如下。
对于索引中的每个段:
SegmentReader和collector.setNextReader(reader, base)。您可以在图层阅读器上使用ir.getSequentialSubReaders()和ir.getSubReaderStarts()获得这些信息。所以,- `reader` _may_ be used by `collector` to load sort fields/caches during collection, and additional fields to augment search result when collection is done,
- `base` is the number added to segment/local docIDs (they start from 0 for each segment) to convert them to index/global docIDs.
collector.setScorer(scorer)的Scorer实现。collector可以在下一阶段使用它来获得文档的评分。虽然如果收集器只计算结果,或者对某些存储字段进行排序,或者感觉如此-- scorer将被忽略。
collected.
scorer.score(),它应该返回当前文档的分数(我骗您不这么做),它是具有与查询匹配的分段/本地文档I的单调递增序列的scorer.score()调用collector.collect(id)。回到您的代码--制作一些实现Scorer的包装器,在每次迭代时使用带有simi更新的字段的单个实例,让包装器的score()方法返回该字段,在循环之前使用setScorer()将该实例插入收集器中。
您还需要lsa.searchOnDoc来返回每个段的结果。
https://stackoverflow.com/questions/5473565
复制相似问题