指南针卢塞恩命中

发布于 2024-10-02 04:35:06 字数 700 浏览 5 评论 0原文

我在上面使用 Lucene 和 Compass,遇到一个问题:

          try {
      
       CompassHits hits = compassQuery.hits();
       for (CompassHit compassHit : hits) {
        if (results.size() >= maxResults) {
         Log.info(this, "Number of results exceeded %,d for query %s", maxResults, query);
         break;
        } else {
    
         results.add((T) compassHit.getData());
        }
       }
       

  } 

当通过 compassHit.getData()); 获取数据并且命中 100 时,它会重新执行搜索,是否有可能将其更改为 200 或更多?

编辑:

来自 wiki apache org:

“迭代所有命中很慢有两个原因。首先,当您需要超过 100 个命中时,返回 Hits 对象的 search() 方法会在内部重新执行搜索”。

我的问题是否有机会将此值“100”更改为“200”? 但重要的是我使用指南针或原始 Lucene。

I use Lucene and Compass on it and I have a problem:

          try {
      
       CompassHits hits = compassQuery.hits();
       for (CompassHit compassHit : hits) {
        if (results.size() >= maxResults) {
         Log.info(this, "Number of results exceeded %,d for query %s", maxResults, query);
         break;
        } else {
    
         results.add((T) compassHit.getData());
        }
       }
       

  } 

When the data is geting by compassHit.getData()); and it's a 100 hit it re-execute the search, is there any possibility to change it to 200 or more?

EDIT:

From wiki apache org:

"Iterating over all hits is slow for two reasons. Firstly, the search() method that returns a Hits object re-executes the search internally when you need more than 100 hits".

And my question is there opportunity to change this value "100" to "200"?
but important is that I use compass nor a raw Lucene.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-10-09 04:35:06

我查看了 2.9.2 中 Hits 的来源。它是硬编码的。看起来它是硬编码的

 Hits(Searcher s, Query q, Filter f) throws IOException {
    this.weight = q.weight(s);
    this.searcher = s;
    this.filter = f;
    this.nDeletions = countDeletions(s);
    getMoreDocs(50);
    this.lengthAtStart = this.length;
  }

如果您没有使用 Compass,您可以按照 JavaDoc for Hits 中的说明进行操作,该说明建议进行替换

,例如可以使用 TopDocCollector 和 TopDocs:

  TopDocCollector collector = new TopDocCollector(hitsPerPage);
   searcher.search(query, collector);
   ScoreDoc[] hits = collector.topDocs().scoreDocs;
   for (int i = 0; i < hits.length; i++) {
     int docId = hits[i].doc;
     Document d = searcher.doc(docId);
     // do something with current hit
     ...

但是既然您使用了 Compass,除非您愿意重写部分内容指南针,我想你被困住了

I looked at the source for Hits in 2.9.2. It's hard coded. It looks like it's hard coded

 Hits(Searcher s, Query q, Filter f) throws IOException {
    this.weight = q.weight(s);
    this.searcher = s;
    this.filter = f;
    this.nDeletions = countDeletions(s);
    getMoreDocs(50);
    this.lengthAtStart = this.length;
  }

If you weren't using Compass, you could follow the instructions in the JavaDoc for Hits which suggests a replacement

Instead e. g. TopDocCollector and TopDocs can be used:

  TopDocCollector collector = new TopDocCollector(hitsPerPage);
   searcher.search(query, collector);
   ScoreDoc[] hits = collector.topDocs().scoreDocs;
   for (int i = 0; i < hits.length; i++) {
     int docId = hits[i].doc;
     Document d = searcher.doc(docId);
     // do something with current hit
     ...

But since you are, unless you are willing to rewrite part of Compass, I think you are stuck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文