首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java lucene的语义搜索结果

java lucene的语义搜索结果
EN

Stack Overflow用户
提问于 2011-03-29 13:46:55
回答 1查看 857关注 0票数 1

我在Lucene上实现了潜在的语义分析

算法的结果是由2列组成的矩阵,其中第一列是文档的索引,第二列是相似度。

我想在org.apache.lucene.search.Collector中写入对Searcher的方法搜索的响应,但是我不知道如何在收集器对象中设置结果。

搜索方法的代码是:

代码语言:javascript
复制
    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值的正确步骤。

你能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2011-04-01 09:59:13

我不太明白你为什么决定把LSI推入Searcher

Weight获取文本查询看起来特别模糊--为什么不使用原始查询并跳过所有(中断的)转换?

但是Collector的处理方式如下。

对于索引中的每个段:

  1. 为其提供相应的SegmentReadercollector.setNextReader(reader, base)。您可以在图层阅读器上使用ir.getSequentialSubReaders()ir.getSubReaderStarts()获得这些信息。所以,

代码语言:javascript
复制
- `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. 

  1. 为它提供了一个带有collector.setScorer(scorer)Scorer实现。

collector可以在下一阶段使用它来获得文档的评分。虽然如果收集器只计算结果,或者对某些存储字段进行排序,或者感觉如此-- scorer将被忽略。

collected.

  • Repeatedly实例上唯一的方法收集器调用的方法是scorer.score(),它应该返回当前文档的分数(我骗您不这么做),它是具有与查询匹配的分段/本地文档I的单调递增序列的scorer.score()调用collector.collect(id)

回到您的代码--制作一些实现Scorer的包装器,在每次迭代时使用带有simi更新的字段的单个实例,让包装器的score()方法返回该字段,在循环之前使用setScorer()将该实例插入收集器中。

您还需要lsa.searchOnDoc来返回每个段的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5473565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档