mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-23 02:31:52 +01:00
fix it
This commit is contained in:
parent
ec83d01dca
commit
d4245582a7
@ -15,42 +15,38 @@ import com.twitter.search.queryparser.visitors.DetectAnnotationVisitor;
|
|||||||
* A visitor that collects node ranks from :r annotation in the query
|
* A visitor that collects node ranks from :r annotation in the query
|
||||||
*/
|
*/
|
||||||
public class QueryRankVisitor extends DetectAnnotationVisitor {
|
public class QueryRankVisitor extends DetectAnnotationVisitor {
|
||||||
private final IdentityHashMap<Query, Integer> nodeToRankMap = Maps.newIdentityHashMap();
|
private final IdentityHashMap<Query, Integer> nodeToRankMap = Maps.newIdentityHashMap();
|
||||||
|
|
||||||
public QueryRankVisitor() {
|
public QueryRankVisitor() {
|
||||||
super(Annotation.Type.NODE_RANK);
|
super(Annotation.Type.NODE_RANK);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean visitBooleanQuery(BooleanQuery query) throws QueryParserException {
|
|
||||||
if (query.hasAnnotationType(Annotation.Type.NODE_RANK)) {
|
|
||||||
collectNodeRank(query.getAnnotationOf(Annotation.Type.NODE_RANK).get(), query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean found = false;
|
@Override
|
||||||
for (Query child : query.getChildren()) {
|
protected boolean visitBooleanQuery(BooleanQuery query) throws QueryParserException {
|
||||||
found |= child.accept(this);
|
if (query.hasAnnotationType(Annotation.Type.NODE_RANK)) {
|
||||||
}
|
collectNodeRank(query.getAnnotationOf(Annotation.Type.NODE_RANK).get(), query);
|
||||||
return found;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return query.getChildren().stream().anyMatch(child -> child.accept(this));
|
||||||
protected boolean visitQuery(Query query) throws QueryParserException {
|
|
||||||
if (query.hasAnnotationType(Annotation.Type.NODE_RANK)) {
|
|
||||||
collectNodeRank(query.getAnnotationOf(Annotation.Type.NODE_RANK).get(), query);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
@Override
|
||||||
}
|
protected boolean visitQuery(Query query) throws QueryParserException {
|
||||||
|
if (query.hasAnnotationType(Annotation.Type.NODE_RANK)) {
|
||||||
|
collectNodeRank(query.getAnnotationOf(Annotation.Type.NODE_RANK).get(), query);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void collectNodeRank(Annotation anno, Query query) {
|
return false;
|
||||||
Preconditions.checkArgument(anno.getType() == Annotation.Type.NODE_RANK);
|
}
|
||||||
int rank = (Integer) anno.getValue();
|
|
||||||
nodeToRankMap.put(query, rank);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IdentityHashMap<Query, Integer> getNodeToRankMap() {
|
private void collectNodeRank(Annotation anno, Query query) {
|
||||||
return nodeToRankMap;
|
Preconditions.checkArgument(anno.getType() == Annotation.Type.NODE_RANK);
|
||||||
}
|
int rank = (Integer) anno.getValue();
|
||||||
|
nodeToRankMap.put(query, rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityHashMap<Query, Integer> getNodeToRankMap() {
|
||||||
|
return nodeToRankMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user