Mailing List Archive

Search different terms for different fields (Complex Query)
Please help

In my LuceneDocument, I have three fields (title, library, content) and I
would like to search for 'myText' in the content field AND it should also
match 'myLibrary' in Library field.

"content:myText: AND "library:myLibrary"

It should only return hit if 'myText' is in the content and 'myLibrary' is
in the library field.

I read the Lucene FAG and it mention about complex query but does NOT give
any example. Can someone please help me with some sample code.

Thanks

Here is what the FAG say:
"A more complex queries may contain nested queries with 'and', 'or', 'not'
or 'phrase' relations. Queries may also contains specification of which
document fields to match against the various parts of the query (.e.g.
'authors' and 'title') and hints that may effects the ranking of the matched
documents ('boost' factor)."


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
Re: Search different terms for different fields (Complex Query) [ In reply to ]
Have you tried:
content:myText AND library:myLibrary

Note no quotes and no ':' after myText

If the quote of the FAQ (not FAG, fag is a slang (derogatory?) term for
homosexuals) entry is the real version then there are some typos to fix
there...

Otis


--- Dzung Nguyen <nguyendq35@hotmail.com> wrote:
>
> Please help
>
> In my LuceneDocument, I have three fields (title, library, content)
> and I
> would like to search for 'myText' in the content field AND it should
> also
> match 'myLibrary' in Library field.
>
> "content:myText: AND "library:myLibrary"
>
> It should only return hit if 'myText' is in the content and
> 'myLibrary' is
> in the library field.
>
> I read the Lucene FAG and it mention about complex query but does NOT
> give
> any example. Can someone please help me with some sample code.
>
> Thanks
>
> Here is what the FAG say:
> "A more complex queries may contain nested queries with 'and', 'or',
> 'not'
> or 'phrase' relations. Queries may also contains specification of
> which
> document fields to match against the various parts of the query
> (.e.g.
> 'authors' and 'title') and hints that may effects the ranking of the
> matched
> documents ('boost' factor)."
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
> http://explorer.msn.com/intl.asp
>
>
> --
> To unsubscribe, e-mail:
> <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:lucene-user-help@jakarta.apache.org>
>


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
RE: Search different terms for different fields (Complex Query) [ In reply to ]
It sounds like the "complex" query you are looking
for is a BooleanQuery which links different queries
together.

Maybe:
BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(new Term("content", "yourText")), true, false);
bq.add(new TermQuery(new Term("library", "yourText")), true, false);
... and then pass this Query into the searcher you are using.

I believe that BooleanQuery will return all documents that match
both of the TermQuery(s) you pass in.

Hope this helps, and goodluck,
Stephen Wong

> -----Original Message-----
> From: Dzung Nguyen [mailto:nguyendq35@hotmail.com]
> Sent: Tuesday, December 11, 2001 11:58 AM
> To: lucene-user@jakarta.apache.org
> Subject: Search different terms for different fields (Complex Query)
>
>
>
> Please help
>
> In my LuceneDocument, I have three fields (title, library, content) and I
> would like to search for 'myText' in the content field AND it should also
> match 'myLibrary' in Library field.
>
> "content:myText: AND "library:myLibrary"
>
> It should only return hit if 'myText' is in the content and
> 'myLibrary' is
> in the library field.
>
> I read the Lucene FAG and it mention about complex query but does
> NOT give
> any example. Can someone please help me with some sample code.
>
> Thanks
>
> Here is what the FAG say:
> "A more complex queries may contain nested queries with 'and',
> 'or', 'not'
> or 'phrase' relations. Queries may also contains specification of which
> document fields to match against the various parts of the query (.e.g.
> 'authors' and 'title') and hints that may effects the ranking of
> the matched
> documents ('boost' factor)."
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> --
> To unsubscribe, e-mail:
> <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:lucene-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
Re: Search different terms for different fields (Complex Query) [ In reply to ]
I've posted a MultiFieldQueryParser to this list previously. Search the
archives.

I think you'll find it useful.

Kelvin

----- Original Message -----
From: Stephen Wong <swong@progress.com>
To: Lucene Users List <lucene-user@jakarta.apache.org>
Sent: Wednesday, December 12, 2001 3:02 AM
Subject: RE: Search different terms for different fields (Complex Query)


> It sounds like the "complex" query you are looking
> for is a BooleanQuery which links different queries
> together.
>
> Maybe:
> BooleanQuery bq = new BooleanQuery();
> bq.add(new TermQuery(new Term("content", "yourText")), true, false);
> bq.add(new TermQuery(new Term("library", "yourText")), true, false);
> ... and then pass this Query into the searcher you are using.
>
> I believe that BooleanQuery will return all documents that match
> both of the TermQuery(s) you pass in.
>
> Hope this helps, and goodluck,
> Stephen Wong
>
> > -----Original Message-----
> > From: Dzung Nguyen [mailto:nguyendq35@hotmail.com]
> > Sent: Tuesday, December 11, 2001 11:58 AM
> > To: lucene-user@jakarta.apache.org
> > Subject: Search different terms for different fields (Complex Query)
> >
> >
> >
> > Please help
> >
> > In my LuceneDocument, I have three fields (title, library, content) and
I
> > would like to search for 'myText' in the content field AND it should
also
> > match 'myLibrary' in Library field.
> >
> > "content:myText: AND "library:myLibrary"
> >
> > It should only return hit if 'myText' is in the content and
> > 'myLibrary' is
> > in the library field.
> >
> > I read the Lucene FAG and it mention about complex query but does
> > NOT give
> > any example. Can someone please help me with some sample code.
> >
> > Thanks
> >
> > Here is what the FAG say:
> > "A more complex queries may contain nested queries with 'and',
> > 'or', 'not'
> > or 'phrase' relations. Queries may also contains specification of which
> > document fields to match against the various parts of the query (.e.g.
> > 'authors' and 'title') and hints that may effects the ranking of
> > the matched
> > documents ('boost' factor)."
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:lucene-user-help@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>