Reputation: 610
i am trying to create an edismax query and set the query params like the defType, df, q.op...ect pragmatically. I was able to create a boolean query as below but couldn't set the query parameters. any idea how?
private List<String> getBoostedElevationObj(ResponseBuilder rb) {
SolrQueryRequest req = rb.req;
Query query = rb.getQuery();
List<String> docIds = null;
try {
BooleanQuery docIdsBq = new BooleanQuery();
TermQuery tq2 = new TermQuery(new Term("subscription", "yes"));
docIdsBq.add(tq2, BooleanClause.Occur.MUST);
SolrIndexSearcher solrIndexSearcher = req.getSearcher();
DocList docList = solrIndexSearcher.getDocList(query, docIdsBq, null,
0, 5);
DocIterator docIterator = docList.iterator();
docIds = new ArrayList<String>();
int docId;
Document doc = null;
while (docIterator.hasNext()) {
docId = docIterator.nextDoc();
doc = solrIndexSearcher.doc(docId);
docIds.add(doc.get(idField));
}
} catch (Exception e) {
e.printStackTrace();
}
return docIds;
}
Upvotes: 0
Views: 216
Reputation: 33341
Being that those are query parser parameters, and you are eliminating the query parser in these manually constructed queries, the responsibility for some of that functionality falls to you.
NumericRangeQuery
is appropriate, etc.BooleanQuery
, you must also specify a BooleanClause.Occur
setting, so there is no default operator.some other common params:
getDocList
call, third argument, in the form of a Sort
getDocList
IndexSearcher.doc
call.Also, you should keep in mind, that edismax generally produces a DisjunctionMaxQuery to join clauses, rather than a BooleanQuery, and there are significant differences in how they are scored and constructed. In the case of the BooleanQuery you've created this isn't an issue, since: A - it only has one clause, and B - it's being applied as a filter. However, probably worth keeping in mind if you have other cases in mind here in which that might be an issue.
Upvotes: 1