Very Nice. Thanks! Luke
----- Original Message ----- From: "åç" <[EMAIL PROTECTED]> To: "Lucene Users List" <lucene-user@jakarta.apache.org> Sent: Friday, February 04, 2005 2:12 AM Subject: Re: Parsing The Query: Every document that doesn't have a field containing x I think you may can use a filter to get right result! See examlples below package lia.advsearching; import junit.framework.TestCase; import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.QueryFilter; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.RAMDirectory; public class SecurityFilterTest extends TestCase { private RAMDirectory directory; protected void setUp() throws Exception { directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true); // Elwood Document document = new Document(); document.add(Field.Keyword("owner", "elwood")); document.add(Field.Text("keywords", "elwoods sensitive info")); writer.addDocument(document); // Jake document = new Document(); document.add(Field.Keyword("owner", "jake")); document.add(Field.Text("keywords", "jakes sensitive info")); writer.addDocument(document); writer.close(); } public void testSecurityFilter() throws Exception { TermQuery query = new TermQuery(new Term("keywords", "info")); IndexSearcher searcher = new IndexSearcher(directory); Hits hits = searcher.search(query); assertEquals("Both documents match", 2, hits.length()); QueryFilter jakeFilter = new QueryFilter( new TermQuery(new Term("owner", "jake"))); hits = searcher.search(query, jakeFilter); assertEquals(1, hits.length()); assertEquals("elwood is safe", "jakes sensitive info", hits.doc(0).get("keywords")); } } On Thu, 3 Feb 2005 13:04:50 -0500, Luke Shannon <[EMAIL PROTECTED]> wrote: > Hello; > > I have a query that finds document that contain fields with a specific > value. > > query1 = QueryParser.parse("jpg", "kcfileupload", new StandardAnalyzer()); > > This works well. > > I would like a query that find documents containing all kcfileupload fields > that don't contain jpg. > > The example I found in the book that seems to relate shows me how to find > documents without a specific term: > > QueryParser parser = new QueryParser("contents", analyzer); > parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND); > > But than it says: > > 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? > > The API says: > > a plus (+) or a minus (-) sign, indicating that the clause is required or > prohibited respectively; > > I have been playing around with using the minus character without much luck. > > Can someone give point me in the right direction to figure this out? > > Thanks, > > Luke > > --------------------------------------------------------------------- > 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]