Reputation: 1141
I'm searching for documents that contain two terms "one two" in different fields (e.g. title, content etc.). An example in PyLucene:
query = "one two"
clauses = []
for field in fields:
clauses.append(BooleanClause.Occur.SHOULD)
query = MultiFieldQueryParser.parse(Version.LUCENE_CURRENT, query, fields, clauses, analyzer)
I would like to get all documents that contain the term ("one" or "two") and ("one" and "two") and the documents that contain both should get a higher score. When I use a query like "one and two" or "one two"~n I get only that documents.
Is there a way to boost something like multiple matches?
Thanks.
Upvotes: 0
Views: 352
Reputation: 5005
If you're looking for boosting by a certain value "one two", you can use the proximity query boosting provided by SpanNearQuery
http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/spans/SpanNearQuery.html
For instance in Java you would have something like: ...
SpanTermQuery[] spanQueryClauses = new SpanTermQuery[terms.length];
for (int i = 0; i < terms.length; i++) {
spanQueryClauses[i] = new SpanTermQuery(terms[i]);
}
SpanNearQuery spanNearQuery = new SpanNearQuery(
spanQueryClauses, slop, true);
spanNearQuery.setBoost(2.0f);
Upvotes: 0