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 tony yin <ga...@gmail.com> on 2006/10/13 09:59:48 UTC

advanced search

I wanta search several fields use NOT condition, but how?
for example:
I store "test" in {"id", "name", "value", ...} fields.
now I search "test" NOT in "id". That's it.

Can anyone help me?


-- 
Kindly Regards

Tony
===============================

Re: advanced search

Posted by Doron Cohen <DO...@il.ibm.com>.
Terry Steichen <te...@net-frame.com> wrote on 13/10/2006 08:01:11:
> You can just add a field to your indexed docs that always evaluates to a
> fixed value.  Then you can do queries like: +doc:1 -id:test

Alternatively you can use MatchAllDocsQuery, e.g.

    BooleanQuery bq = new BooleanQuery();
    bq.add(new MatchAllDocsQuery(),Occur.SHOULD);
    bq.add(new TermQuery(new Term("id","test")),Occur.MUST_NOT);

>
> karl wettin wrote:
> >
> > 13 okt 2006 kl. 09.59 skrev tony yin:
> >
> >> I wanta search several fields use NOT condition, but how?
> >> for example:
> >> I store "test" in {"id", "name", "value", ...} fields.
> >> now I search "test" NOT in "id". That's it.
> >>
> >> Can anyone help me?
> >
> > You will not get any matchs looking for just a boolean NOT-clause. It
> > has to be combined with something that matches. Perhaps a
> > MatchAllDocumentsQuery will do it for you.
> >
> > But to answer your question: a not-query is a Clause of a BooleanQuery.
> >
> >
> > ---------------------------------------------------------------------
> > 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: advanced search

Posted by Terry Steichen <te...@net-frame.com>.
You can just add a field to your indexed docs that always evaluates to a 
fixed value.  Then you can do queries like: +doc:1 -id:test

karl wettin wrote:
>
> 13 okt 2006 kl. 09.59 skrev tony yin:
>
>> I wanta search several fields use NOT condition, but how?
>> for example:
>> I store "test" in {"id", "name", "value", ...} fields.
>> now I search "test" NOT in "id". That's it.
>>
>> Can anyone help me?
>
> You will not get any matchs looking for just a boolean NOT-clause. It 
> has to be combined with something that matches. Perhaps a 
> MatchAllDocumentsQuery will do it for you.
>
> But to answer your question: a not-query is a Clause of a BooleanQuery.
>
>
> ---------------------------------------------------------------------
> 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: advanced search

Posted by karl wettin <ka...@gmail.com>.
13 okt 2006 kl. 09.59 skrev tony yin:

> I wanta search several fields use NOT condition, but how?
> for example:
> I store "test" in {"id", "name", "value", ...} fields.
> now I search "test" NOT in "id". That's it.
>
> Can anyone help me?

You will not get any matchs looking for just a boolean NOT-clause. It  
has to be combined with something that matches. Perhaps a  
MatchAllDocumentsQuery will do it for you.

But to answer your question: a not-query is a Clause of a BooleanQuery.


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