You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Clemens Wyss <cl...@mysign.ch> on 2011/06/29 17:25:37 UTC

negative wildcard query

Say I have a document with field "f1". How can I search Documents which have not "test" in field "f"
I tried:
-f: *test*
f: -*test*
f: NOT *test*

but no luck. Using WildCardQuery class...
Any advices?

Thx
Clemens

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


AW: negative wildcard query

Posted by Clemens Wyss <cl...@mysign.ch>.
Thx!

> -----Ursprüngliche Nachricht-----
> Von: Uwe Schindler [mailto:uwe@thetaphi.de]
> Gesendet: Donnerstag, 30. Juni 2011 10:32
> An: java-user@lucene.apache.org
> Betreff: RE: negative wildcard query
> 
> Pure negative queries do not work, you have to add a MUST clause that hits
> all documents, e.g. MatchAllDocsQuery:
> 
> query = new BooleanQuery();
> query.add(new MatchAllDocsQuery(), Occur.MUST) query.add(new
> WildcardQuery(new Term( "f", "*test*" )), Occur.MUST_NOT );
> 
> Uwe
> 
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe@thetaphi.de
> 
> 
> > -----Original Message-----
> > From: Clemens Wyss [mailto:clemensdev@mysign.ch]
> > Sent: Thursday, June 30, 2011 9:44 AM
> > To: java-user@lucene.apache.org
> > Subject: AW: negative wildcard query
> >
> > My testcase/context:
> >
> > query = new BooleanQuery();
> > query.add( new WildcardQuery( new Term( "f", "*test*" ) ),
> > Occur.MUST_NOT ); filter = new QueryWrapperFilter( query ); result =
> > indexSearcher.search( new WildcardQuery( new Term( "description",
> > "*happy*" ) ), filter, 10 );
> >
> > The filter never ever lets any documents through...when calling
> >
> > result = indexSearcher.search( new WildcardQuery( new Term(
> > "description", "*happy*" ) ), 10 );
> >
> > I have hits...
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Clemens Wyss [mailto:clemensdev@mysign.ch]
> > > Gesendet: Donnerstag, 30. Juni 2011 05:37
> > > An: java-user@lucene.apache.org
> > > Betreff: AW: negative wildcard query
> > >
> > > Karl, I just saw, that I had a typo in my initial post. It should be:
> > >
> > > Say I have a document with a single field "f". How can I search
> > > Documents which have not "test" in field "f"
> > > I tried:
> > > -f: *test*
> > > f: -*test*
> > > f: NOT *test*
> > >
> > > but no luck. Using WildCardQuery class...
> > > Any advices?
> > >
> > > Thx
> > > Clemens
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Karl Wettin [mailto:karl.wettin@gmail.com]
> > > > Gesendet: Mittwoch, 29. Juni 2011 22:36
> > > > An: java-user@lucene.apache.org
> > > > Betreff: Re: negative wildcard query
> > > >
> > > > You'll also need things to exclude from, eg a MatchAllDocsQuery.
> > > >
> > > > 	karl
> > > >
> > > > 29 jun 2011 kl. 17.25 skrev Clemens Wyss:
> > > >
> > > > > Say I have a document with field "f1". How can I search
> > > > > Documents which
> > > > have not "test" in field "f"
> > > > > I tried:
> > > > > -f: *test*
> > > > > f: -*test*
> > > > > f: NOT *test*
> > > > >
> > > > > but no luck. Using WildCardQuery class...
> > > > > Any advices?
> > > > >
> > > > > Thx
> > > > > Clemens
> > > > >
> > > > > ----------------------------------------------------------------
> > > > > --
> > > > > --
> > > > > - To unsubscribe, e-mail:
> > > > > java-user-unsubscribe@lucene.apache.org
> > > > > For additional commands, e-mail:
> > > > > java-user-help@lucene.apache.org
> > > > >
> > > >
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: negative wildcard query

Posted by Uwe Schindler <uw...@thetaphi.de>.
Pure negative queries do not work, you have to add a MUST clause that hits
all documents, e.g. MatchAllDocsQuery:

query = new BooleanQuery();
query.add(new MatchAllDocsQuery(), Occur.MUST)
query.add(new WildcardQuery(new Term( "f", "*test*" )), Occur.MUST_NOT );

Uwe
 
-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Clemens Wyss [mailto:clemensdev@mysign.ch]
> Sent: Thursday, June 30, 2011 9:44 AM
> To: java-user@lucene.apache.org
> Subject: AW: negative wildcard query
> 
> My testcase/context:
> 
> query = new BooleanQuery();
> query.add( new WildcardQuery( new Term( "f", "*test*" ) ),
> Occur.MUST_NOT ); filter = new QueryWrapperFilter( query ); result =
> indexSearcher.search( new WildcardQuery( new Term( "description",
> "*happy*" ) ), filter, 10 );
> 
> The filter never ever lets any documents through...when calling
> 
> result = indexSearcher.search( new WildcardQuery( new Term(
> "description", "*happy*" ) ), 10 );
> 
> I have hits...
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Clemens Wyss [mailto:clemensdev@mysign.ch]
> > Gesendet: Donnerstag, 30. Juni 2011 05:37
> > An: java-user@lucene.apache.org
> > Betreff: AW: negative wildcard query
> >
> > Karl, I just saw, that I had a typo in my initial post. It should be:
> >
> > Say I have a document with a single field "f". How can I search
> > Documents which have not "test" in field "f"
> > I tried:
> > -f: *test*
> > f: -*test*
> > f: NOT *test*
> >
> > but no luck. Using WildCardQuery class...
> > Any advices?
> >
> > Thx
> > Clemens
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Karl Wettin [mailto:karl.wettin@gmail.com]
> > > Gesendet: Mittwoch, 29. Juni 2011 22:36
> > > An: java-user@lucene.apache.org
> > > Betreff: Re: negative wildcard query
> > >
> > > You'll also need things to exclude from, eg a MatchAllDocsQuery.
> > >
> > > 	karl
> > >
> > > 29 jun 2011 kl. 17.25 skrev Clemens Wyss:
> > >
> > > > Say I have a document with field "f1". How can I search Documents
> > > > which
> > > have not "test" in field "f"
> > > > I tried:
> > > > -f: *test*
> > > > f: -*test*
> > > > f: NOT *test*
> > > >
> > > > but no luck. Using WildCardQuery class...
> > > > Any advices?
> > > >
> > > > Thx
> > > > Clemens
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > > >
> > >
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


AW: negative wildcard query

Posted by Clemens Wyss <cl...@mysign.ch>.
My testcase/context:

query = new BooleanQuery();
query.add( new WildcardQuery( new Term( "f", "*test*" ) ), Occur.MUST_NOT );
filter = new QueryWrapperFilter( query );
result = indexSearcher.search( new WildcardQuery( new Term( "description", "*happy*" ) ), filter, 10 );

The filter never ever lets any documents through...when calling

result = indexSearcher.search( new WildcardQuery( new Term( "description", "*happy*" ) ), 10 );

I have hits...

> -----Ursprüngliche Nachricht-----
> Von: Clemens Wyss [mailto:clemensdev@mysign.ch]
> Gesendet: Donnerstag, 30. Juni 2011 05:37
> An: java-user@lucene.apache.org
> Betreff: AW: negative wildcard query
> 
> Karl, I just saw, that I had a typo in my initial post. It should be:
> 
> Say I have a document with a single field "f". How can I search Documents
> which have not "test" in field "f"
> I tried:
> -f: *test*
> f: -*test*
> f: NOT *test*
> 
> but no luck. Using WildCardQuery class...
> Any advices?
> 
> Thx
> Clemens
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Karl Wettin [mailto:karl.wettin@gmail.com]
> > Gesendet: Mittwoch, 29. Juni 2011 22:36
> > An: java-user@lucene.apache.org
> > Betreff: Re: negative wildcard query
> >
> > You'll also need things to exclude from, eg a MatchAllDocsQuery.
> >
> > 	karl
> >
> > 29 jun 2011 kl. 17.25 skrev Clemens Wyss:
> >
> > > Say I have a document with field "f1". How can I search Documents
> > > which
> > have not "test" in field "f"
> > > I tried:
> > > -f: *test*
> > > f: -*test*
> > > f: NOT *test*
> > >
> > > but no luck. Using WildCardQuery class...
> > > Any advices?
> > >
> > > Thx
> > > Clemens
> > >
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


AW: negative wildcard query

Posted by Clemens Wyss <cl...@mysign.ch>.
Karl, I just saw, that I had a typo in my initial post. It should be:

Say I have a document with a single field "f". How can I search Documents which have not "test" in field "f"
I tried:
-f: *test*
f: -*test*
f: NOT *test*

but no luck. Using WildCardQuery class...
Any advices?

Thx
Clemens 

> -----Ursprüngliche Nachricht-----
> Von: Karl Wettin [mailto:karl.wettin@gmail.com]
> Gesendet: Mittwoch, 29. Juni 2011 22:36
> An: java-user@lucene.apache.org
> Betreff: Re: negative wildcard query
> 
> You'll also need things to exclude from, eg a MatchAllDocsQuery.
> 
> 	karl
> 
> 29 jun 2011 kl. 17.25 skrev Clemens Wyss:
> 
> > Say I have a document with field "f1". How can I search Documents which
> have not "test" in field "f"
> > I tried:
> > -f: *test*
> > f: -*test*
> > f: NOT *test*
> >
> > but no luck. Using WildCardQuery class...
> > Any advices?
> >
> > Thx
> > Clemens
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: negative wildcard query

Posted by Karl Wettin <ka...@gmail.com>.
You'll also need things to exclude from, eg a MatchAllDocsQuery.

	karl

29 jun 2011 kl. 17.25 skrev Clemens Wyss:

> Say I have a document with field "f1". How can I search Documents which have not "test" in field "f"
> I tried:
> -f: *test*
> f: -*test*
> f: NOT *test*
> 
> but no luck. Using WildCardQuery class...
> Any advices?
> 
> Thx
> Clemens
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org