FAQ
Hi,

I have two question regarding phrase query :

1) How can I execute a phrase query over multiple fields ? I can only
get PhraseQuery to work over a single field - For eg something like
this :

PhraseQuery query = new PhraseQuery();
query.setSlop(10);
String[] phrase = { "george", "bush" };
for (String word : phrase) {
query.add(new Term(field, word));
}

2) Is there a way to execute a phrase query along with
MultiFieldQueryParser ? So if I have a query {A B} and fields F1 and
F2, I want the query to be something like this :
(F1:A F2:A) (F1:B F2:B) (F1:"A B"~10 F2:"A B"~10)

MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
Version.LUCENE_30, fields, new SnowballAnalyzer(
Version.LUCENE_30, "English"), boosts);
Query query = queryParser.parse(queryString);

Thanks,
amg

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

Search Discussions

  • Ian Lea at Jan 20, 2011 at 3:00 pm
    No and No.

    Alternative approaches might include building a general "contents"
    field holding any/all searchable fields or building up the query
    yourself. The latter is quite straightforward:

    BooleanQuery bq = new BooleanQuery();
    PhraseQuery pq1 = ...;
    PhraseQuery pq2 = ...;
    bq.add(pq1, ...);
    bq.add(pq2, ...);
    etc.


    --
    Ian.

    On Thu, Jan 20, 2011 at 3:13 AM, amg qas wrote:
    Hi,

    I have two question regarding phrase query :

    1) How can I execute a phrase query over multiple fields ? I can only
    get PhraseQuery to work over a single field - For eg something like
    this :

    PhraseQuery query = new PhraseQuery();
    query.setSlop(10);
    String[] phrase = { "george", "bush" };
    for (String word : phrase) {
    query.add(new Term(field, word));
    }

    2) Is there a way to execute a phrase query along with
    MultiFieldQueryParser ? So if I have a query {A B} and fields F1 and
    F2, I want the query to be something like this :
    (F1:A F2:A) (F1:B F2:B) (F1:"A B"~10 F2:"A B"~10)

    MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
    Version.LUCENE_30, fields, new SnowballAnalyzer(
    Version.LUCENE_30, "English"), boosts);
    Query query = queryParser.parse(queryString);

    Thanks,
    amg

    ---------------------------------------------------------------------
    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
  • Amg qas at Jan 22, 2011 at 6:56 pm
    Thanks Ian. The alternative approach you have mentioned works for me.

    -amg
    On Thu, Jan 20, 2011 at 6:59 AM, Ian Lea wrote:
    No and No.

    Alternative approaches might include building a general "contents"
    field holding any/all searchable fields or building up the query
    yourself.  The latter is quite straightforward:

    BooleanQuery bq = new BooleanQuery();
    PhraseQuery pq1 = ...;
    PhraseQuery pq2 = ...;
    bq.add(pq1, ...);
    bq.add(pq2, ...);
    etc.


    --
    Ian.

    On Thu, Jan 20, 2011 at 3:13 AM, amg qas wrote:
    Hi,

    I have two question regarding phrase query :

    1) How can I execute a phrase query over multiple fields ? I can only
    get PhraseQuery to work over a single field - For eg something like
    this :

    PhraseQuery query = new PhraseQuery();
    query.setSlop(10);
    String[] phrase = { "george", "bush" };
    for (String word : phrase) {
    query.add(new Term(field, word));
    }

    2) Is there a way to execute a phrase query along with
    MultiFieldQueryParser ? So if I have a query {A B} and fields F1 and
    F2, I want the query to be something like this :
    (F1:A F2:A) (F1:B F2:B) (F1:"A B"~10 F2:"A B"~10)

    MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
    Version.LUCENE_30, fields, new SnowballAnalyzer(
    Version.LUCENE_30, "English"), boosts);
    Query query = queryParser.parse(queryString);

    Thanks,
    amg

    ---------------------------------------------------------------------
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJan 20, '11 at 3:14a
activeJan 22, '11 at 6:56p
posts3
users2
websitelucene.apache.org

2 users in discussion

Amg qas: 2 posts Ian Lea: 1 post

People

Translate

site design / logo © 2022 Grokbase