English 中文(简体)
我如何利用Lucene搜寻不含术语的文件?
原标题:How can I use Lucene to search for documents that do not contain a term?
  • 时间:2011-11-04 15:15:34
  •  标签:
  • java
  • lucene

我知道,Lucene 文件

Note: The NOT operator cannot be used with just one term. For example, the following search will return no results:

NOT “jakarta apache”

然而,我要提出一个问题,即归还所有载有任期的文件。 我研究了一起铺设href=

If I index the following two documents

Doc0: content:The quick brown fox jumps over the lazy dog.
Doc1: (empty string)

查询<代码>*:* -content:fox在我只想一份文件时将这两份文件退回。

The RegexQuery content:^((?!fox).)*$ suggested by this StackOverflow answer returns one document but it does not seem to be working correctly because content:^((?!foo).)*$ returns one document as well when I expect it to return two documents.

我知道我想要做的工作对业绩的影响。 问询只能用几份文件处理,因此我对业绩不感到担忧。

是否有办法撰写卢塞恩的问询,以获得我想要的东西?

最佳回答

您可以使用与一切相匹配的术语,并排除以下术语:

IndexSearcher searcher = new IndexSearcher("path_to_index");
MatchAllDocsQuery everyDocClause = new MatchAllDocsQuery();
TermQuery termClause = new TermQuery(new Term("text", "exclude_term"));
BooleanQuery query = new BooleanQuery();
query.add(everyDocClause, BooleanClause.Occur.MUST);
query.add(termClause, BooleanClause.Occur.MUST_NOT);
Hits hits = searcher.search(query);  

Else, have a dummy field which some fixed value and use query

+dummy_field:dummy_value -exclude_term
问题回答

您是否可以把“人工”引向每份文件,然后寻找“附加的,而不是你想要避免的”。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签