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 Krishnendra Nandi <kr...@hewitt.com> on 2006/11/09 13:59:07 UTC

Specific Query on multiple fields

Hi All,

How do we use a specific query on multiple fields ?

for eg.
I have to run a query "jakarta tomcat" (the string which i give in my 
textbox is with double quotes as I have to get the string 'jakarta tomcat' 
together)
on mutiple fields like "content" ,"title","examples" 

Also if I have a specific string query like "Jakarta:" How do i get that? 
would it not try to search a field with the name jakarta ? 
As far as I can see it ignores the ':' and tries to search only on 
jakarta.

All possible help is welcome.
Thanks and Regards
Krishnendra Nandi
Hewitt Associates India (Pvt.) Ltd.
Unitech World
Sector-39, Gurgaon
Haryana-India
 
The information contained in this e-mail and any accompanying documents may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message, including any attachments. Any dissemination, distribution or other use of the contents of this message by anyone other than the intended recipient 
is strictly prohibited.



Re: Specific Query on multiple fields

Posted by Patrick Turcotte <pa...@gmail.com>.
Hi,

How do we use a specific query on multiple fields ?
>
> for eg.
> I have to run a query "jakarta tomcat" (the string which i give in my
> textbox is with double quotes as I have to get the string 'jakarta tomcat'
> together)
> on mutiple fields like "content" ,"title","examples"


Take a look at org.apache.lucene.queryParser.MultiFieldQueryParser, it
probably does what you want.

Patrick

Re: Specific Query on multiple fields

Posted by Erick Erickson <er...@gmail.com>.
Well, if I think you can create three PhraseQueries and combine them  in a
BooleanQuery with SHOULD. That is
PhraseQuery pq1 = new PhraseQuery();
pq1.add(new Term("content", "jakarta tomcat"));
pq2.add(new Term("title", "jakarta tomcat"));

BooleanQuery bq = new BooleanQuery();
bq.add(pq1, BooleanClause.Occur.SHOULD);
bq.add(pq2, BoleanClause.Occur.SHOULD);

and then use the bq for your searcher.

Note: you may have to do a separate add for pq, once for "jakarta" and once
for "tomcat"...

As far as the second question is concerned, you probably are running afoul
of the analyzer you use either at index time or search time or both. If you
use StandardAnalyzer, it will strip out the colon ':', so searching only for
"jakarta" is exactly what I would expect. Something like WhitespaceAnalyzer
might be a better bet...

Hope this helps
Erick



On 11/9/06, Krishnendra Nandi <kr...@hewitt.com> wrote:
>
> Hi All,
>
> How do we use a specific query on multiple fields ?
>
> for eg.
> I have to run a query "jakarta tomcat" (the string which i give in my
> textbox is with double quotes as I have to get the string 'jakarta tomcat'
> together)
> on mutiple fields like "content" ,"title","examples"
>
> Also if I have a specific string query like "Jakarta:" How do i get that?
> would it not try to search a field with the name jakarta ?
> As far as I can see it ignores the ':' and tries to search only on
> jakarta.
>
> All possible help is welcome.
> Thanks and Regards
> Krishnendra Nandi
> Hewitt Associates India (Pvt.) Ltd.
> Unitech World
> Sector-39, Gurgaon
> Haryana-India
>
> The information contained in this e-mail and any accompanying documents
> may contain information that is confidential or otherwise protected from
> disclosure. If you are not the intended recipient of this message, or if
> this message has been addressed to you in error, please immediately alert
> the sender by reply e-mail and then delete this message, including any
> attachments. Any dissemination, distribution or other use of the contents of
> this message by anyone other than the intended recipient
> is strictly prohibited.
>
>
>
>