简体   繁体   English

在特定文档上搜索 lucene

[英]search lucene on a specific document

I'm using Lucene with java to index some text documents.我正在使用 Lucene 和 java 来索引一些文本文档。 Now, after I get some top documents for a keyword search, I want to further refine my search and search only those top documents with some additional keywords, so each document once.现在,在我获得一些用于关键字搜索的热门文档后,我想进一步优化我的搜索并只搜索那些带有一些附加关键字的热门文档,因此每个文档一次。 Can somebody tell me on how I can search a specific document with a specific keyword, not the whole index, but lets say just 123.xml with keywords "bla blah".有人可以告诉我如何使用特定关键字搜索特定文档,而不是整个索引,但可以说只使用关键字“bla blah”的 123.xml。

thanx in advance提前谢谢

If you want to refine your search, you should use filters (look at IndexSearcher如果你想优化你的搜索,你应该使用过滤器(查看 IndexSearcher

search(Query query,
     Filter filter,
     int n,
     Sort sort)

). )。 Filters will be executed on the result set and are the proper way to implement refined searches.过滤器将在结果集上执行,并且是实现精细搜索的正确方法。

Have a look at this page to find out how to use filters: http://www.javaranch.com/journal/2009/02/filtering-a-lucene-search.html查看此页面以了解如何使用过滤器: http://www.javaranch.com/journal/2009/02/filtering-a-lucene-search.html

Anyway:反正:

If you want to search in just one document you can either take the one document, store it in a RAMDirectory and search in the RAMDirectory just as you would in your normal index.如果您只想搜索一个文档,您可以获取一个文档,将其存储在 RAMDirectory 中,然后像在普通索引中一样在 RAMDirectory 中搜索。 Or you can have a field containig unique identifyers for each document and add this to your query eg "contant:(bla blah) and uniqe_doc_id:(doc1)"或者您可以为每个文档设置一个包含唯一标识符的字段,并将其添加到您的查询中,例如“contant:(bla blah) and uniqe_doc_id:(doc1)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM