Hello; I think Chris's approach might be helpfull, but I can't seems to get it to work.
So since I running out of time and I still need to figure out "starts with" and "ends with" queries, I have implemented a hacky solution to getting all documents with a kcfileupload field present that does not contain jpg: query1 = QueryParser.parse("jpg", "kcfileupload", new StandardAnalyzer()); query2 = QueryParser.parse("stillhere", "olfaithfull", new StandardAnalyzer());//each document contains this BooleanQuery typeNegativeSearch = new BooleanQuery(); typeNegativeSearch.add(query1, false, true); typeNegativeSearch.add(query2, true, false); What gets returned are all the documents without a kcfileupload = jpg. This includes documents that don't even have a kcfileupload. When I go through the results before displaying I check to make sure there is a "kcfileupload" field. This is not a good solution, and I hope to replace it soon. If anyone has ideas please let me know. Luke ----- Original Message ----- From: "Chris Hostetter" <[EMAIL PROTECTED]> To: "Lucene Users List" <lucene-user@jakarta.apache.org> Sent: Friday, February 04, 2005 3:03 PM Subject: Re: Parsing The Query: Every document that doesn't have a field containing x 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 <[EMAIL PROTECTED]> : 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: [EMAIL PROTECTED] : For additional commands, e-mail: [EMAIL PROTECTED] : -Hoss --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]