Another approach...
You can make a Filter that is the inverse of the output from another
filter, which means you can make a QueryFilter on the search, then wrap it
in your inverse Filter.
you can't execute a query on a filter without having a Query object, but
you can just apply the Filter directly to an IndexReader yourself, and get
back a BitSet containing the docIds of everydocument that does not contain
your term.
something like this should work...
class NotFilter extends Filter {
private Filter wraped;
public NotFilter(Filter w) {
wraped = w;
}
public BitSet bits(IndexReader r) {
BitSet b = wraped.bits(r);
b.flip(0,b.size());
return b;
}
}
...
BitSet results = (new NotFilter
(new QueryFilter
(new TermQuery(new Term("f","x"))))).bits(reader);
: Date: Thu, 3 Feb 2005 19:51:36 +0100
: From: Kelvin Tan <kelvin-lists@relevanz.com>
: Reply-To: Lucene Users List <lucene-user@jakarta.apache.org>
: To: Lucene Users List <lucene-user@jakarta.apache.org>
: Subject: Re: Parsing The Query: Every document that doesn't have a field
: containing x
:
: Alternatively, add a dummy field-value to all documents, like doc.add(Field.Keyword("foo",
"bar"))
:
: Waste of space, but allows you to perform negated queries.
:
: On Thu, 03 Feb 2005 19:19:15 +0100, Maik Schreiber wrote:
: >> Negating a term must be combined with at least one nonnegated
: >> term to return documents; in other words, it isn't possible to
: >> use a query like NOT term to find all documents that don't
: >> contain a term.
: >>
: >> So does that mean the above example wouldn't work?
: >>
: > Exactly. You cannot search for "-kcfileupload:jpg", you need at
: > least one clause that actually _includes_ documents.
: >
: > Do you by chance have a field with known contents? If so, you could
: > misuse that one and include it in your query (perhaps by doing
: > range or wildcard/prefix search). If not, try IndexReader.terms()
: > for building a Query yourself, then use that one for search.
:
:
:
: ---------------------------------------------------------------------
: To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
: For additional commands, e-mail: lucene-user-help@jakarta.apache.org
:
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
|