lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Specific Query on multiple fields
Date Thu, 09 Nov 2006 13:15:28 GMT
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 <krishnendra.nandi@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.
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message