FAQ
Hi,

I'm trying to build my own query. I want to combine several TermQuery
+ 1 PrefixQuery in a BooleanQuery. The Code looks like this:
BooleanQuery bq = new BooleanQuery();

Term t = new Term("field", "");

t.createTerm("foo");
TermQuery tq = new TermQuery(t);
bq.add(tq, Occur.MUST);

t.createTerm("bar");
PrefixQuery pq = new PrefixQuery(t);
bq.add(pq, Occur.MUST);

So bq is my customized BooleanQuery. Searching with this query results
in 0 hits. But working with QueryParser.parse()
and the parameter "foo AND bar*" results in a high number of hits.
Looking at the query string shows the same result
for the QueryParser querystring and the customized BooleanQuery
querystring.
What could be the problem with my customized query?

Sascha

Search Discussions

  • Erick Erickson at Jun 16, 2008 at 1:12 pm
    First, have you tried looking at bq.toString() to see what your query looks
    like?

    But from your code, you're not assigning your createTerm to anything, so
    your
    BQ is constructed from two terms on "field" that have no values. You need
    something like

    bq.add(t.createTerm("foo), Occur.MUST);

    Best
    Erick
    On Mon, Jun 16, 2008 at 4:25 AM, Sascha Fahl wrote:

    Hi,

    I'm trying to build my own query. I want to combine several TermQuery + 1
    PrefixQuery in a BooleanQuery. The Code looks like this:
    BooleanQuery bq = new BooleanQuery();

    Term t = new Term("field", "");

    t.createTerm("foo");
    TermQuery tq = new TermQuery(t);
    bq.add(tq, Occur.MUST);

    t.createTerm("bar");
    PrefixQuery pq = new PrefixQuery(t);
    bq.add(pq, Occur.MUST);

    So bq is my customized BooleanQuery. Searching with this query results in 0
    hits. But working with QueryParser.parse()
    and the parameter "foo AND bar*" results in a high number of hits. Looking
    at the query string shows the same result
    for the QueryParser querystring and the customized BooleanQuery
    querystring.
    What could be the problem with my customized query?

    Sascha

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJun 16, '08 at 8:26a
activeJun 16, '08 at 1:12p
posts2
users2
websitelucene.apache.org

2 users in discussion

Sascha Fahl: 1 post Erick Erickson: 1 post

People

Translate

site design / logo © 2022 Grokbase