Skip to content

Commit

Permalink
test: make topn() behave like a top level query incl custom score com…
Browse files Browse the repository at this point in the history
…putation
  • Loading branch information
romanchyla committed Dec 28, 2021
1 parent 60d6d25 commit d5d9ec0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ public Query parse(FunctionQParser fp) throws SyntaxError {

SortSpec sortSpec = SortSpecParsing.parseSortSpec(sortOrRank, fp.getReq());

Query q;
if (sortSpec.getSort() == null) {
return new SecondOrderQuery(innerQuery,
q = new SecondOrderQuery(innerQuery,
new SecondOrderCollectorTopN(topN));
}
else {
Expand All @@ -616,9 +617,11 @@ public Query parse(FunctionQParser fp) throws SyntaxError {
throw new SyntaxError("I am sorry, you can't use " + sortOrRank + " for topn() sorting. Reason: " + e.getMessage());
}

return new SecondOrderQuery(innerQuery,
q = new SecondOrderQuery(innerQuery,
new SecondOrderCollectorTopN(sortOrRank.toString(), topN, sortOrder));
}

return AqpScoringQueryNodeBuilder.wrapQuery(q, "cite_read_boost", 0.5f);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@
* score = lucene_score * ( classic_factor + modifier )
*/
public class AqpScoringQueryNodeBuilder implements StandardQueryBuilder {


public Query build(QueryNode queryNode) throws QueryNodeException {

AqpAdsabsScoringQueryNode q = (AqpAdsabsScoringQueryNode) queryNode;

Query query = (Query) queryNode.getChildren().get(0).getTag(
QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

ValueSource vs = new SumFloatFunction(new ValueSource[] {
new FloatFieldSource(q.getSource()), // classic score
new ConstValueSource(q.getModifier()) // modifier
});


FunctionQuery functionQuery = new FunctionQuery(vs);
return new CustomScoreQuery(query, functionQuery);

}

AqpAdsabsScoringQueryNode q = (AqpAdsabsScoringQueryNode) queryNode;

Query query = (Query) queryNode.getChildren().get(0).getTag(
QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

return wrapQuery(query, q.getSource(), q.getModifier());

}

public static Query wrapQuery(Query q, String source, float modifier) {
ValueSource vs = new SumFloatFunction(new ValueSource[] {
new FloatFieldSource(source), // classic score
new ConstValueSource(modifier) // modifier of how much lucene score to use
});


FunctionQuery functionQuery = new FunctionQuery(vs);
return new CustomScoreQuery(q, functionQuery);
}

}

0 comments on commit d5d9ec0

Please sign in to comment.