ravi
ravi

Reputation: 277

Lucene Query Boosting

I am reading 2 query from file like,

Query q1 = new QueryParser(Version.LUCENE_CURRENT, "id", analyzer).parse(dis.readLine());
Query q2 = new QueryParser(Version.LUCENE_CURRENT, "id", analyzer).parse(dis.readLine());

I want these query to be combined as one query and give some boost (say by 5) to query 2 i.e q2.

Thanks,
Ravi

Upvotes: 2

Views: 2661

Answers (2)

Adam Paynter
Adam Paynter

Reputation: 46878

I believe this should work:

q2.setBoost(5);

BooleanQuery q3 = new BooleanQuery();
q3.add(q1, BooleanClause.Occur.SHOULD);
q3.add(q2, BooleanClause.Occur.SHOULD);

You searching using the BooleanQuery q3.

Upvotes: 1

ryoung
ryoung

Reputation: 846

I'm not sure if you can boost a query or not. I know you can boost a field when you create the index e.g.

Field field = new Field("id", id, ......);
field.setBoost(0.5);

As far as combining those 2 queries:

String term = dis.readLine() + " AND " + dis.readLine();

Or something to that effect .....

Upvotes: 0

Related Questions