use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class CollapsePhraseSearcher method search.
public Result search(Query query, Execution execution) {
QueryTree tree = query.getModel().getQueryTree();
Item root = tree.getRoot();
if (root != null) {
Item newRoot = root.clone();
newRoot = simplifyPhrases(newRoot);
// to make code nicer if the root is a single term phrase
if (!root.equals(newRoot)) {
tree.setRoot(newRoot);
query.trace("Collapsing single term phrases to single terms", true, 2);
}
}
return execution.search(query);
}
use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class RecallSearcher method search.
@Override
public com.yahoo.search.Result search(Query query, Execution execution) {
String recall = query.properties().getString(recallName);
if (recall == null)
return execution.search(query);
AnyParser parser = new AnyParser(ParserEnvironment.fromExecutionContext(execution.context()));
QueryTree root = parser.parse(Parsable.fromQueryModel(query.getModel()).setQuery("foo").setFilter(recall));
String err;
if (root.getRoot() instanceof NullItem) {
err = "Failed to parse recall parameter.";
} else if (!(root.getRoot() instanceof CompositeItem)) {
err = "Expected CompositeItem root node, got " + root.getClass().getSimpleName() + ".";
} else if (hasRankItem(root.getRoot())) {
query.getModel().getQueryTree().setRoot(root.getRoot());
err = "Recall contains at least one rank item.";
} else {
WordItem placeholder = findOrigWordItem(root.getRoot(), "foo");
if (placeholder == null) {
err = "Could not find placeholder workQuery root.";
} else {
updateFilterTerms(root);
CompositeItem parent = placeholder.getParent();
parent.setItem(parent.getItemIndex(placeholder), query.getModel().getQueryTree().getRoot());
query.getModel().getQueryTree().setRoot(root.getRoot());
query.trace("ANDed recall tree with root workQuery node.", true, 3);
return execution.search(query);
}
}
return new Result(query, ErrorMessage.createInvalidQueryParameter(err));
}
use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class CJKSearcher method search.
@Override
public Result search(Query query, Execution execution) {
Language language = query.getModel().getParsingLanguage();
if (!language.isCjk())
return execution.search(query);
QueryTree tree = query.getModel().getQueryTree();
tree.setRoot(transform(tree.getRoot()));
query.trace("Rewriting for CJK behavior for implicit phrases", true, 2);
return execution.search(query);
}
use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class VespaSearcherTestCase method testMarshalQuerySmallTree.
public void testMarshalQuerySmallTree() {
RankItem root = new RankItem();
QueryTree r = new QueryTree(root);
AndItem recall = new AndItem();
PhraseItem usual = new PhraseItem();
PhraseItem filterPhrase = new PhraseItem(new String[] { "bloody", "expensive" });
WordItem filterWord = new WordItem("silly");
filterPhrase.setFilter(true);
filterWord.setFilter(true);
root.addItem(recall);
usual.addItem(new WordItem("new"));
usual.addItem(new WordItem("york"));
recall.addItem(usual);
recall.addItem(new WordItem("shoes"));
root.addItem(filterPhrase);
recall.addItem(filterWord);
assertEquals("( \"new york\" AND shoes AND silly ) RANK \"bloody expensive\"", searcher.marshalQuery(r));
// TODO: Switch to this 2-way check rather than just 1-way and then also make this actually treat filter terms correctly
// assertMarshals(root)
}
use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class VespaSearcherTestCase method testMarshalQuery.
public void testMarshalQuery() {
RankItem root = new RankItem();
QueryTree r = new QueryTree(root);
AndItem recall = new AndItem();
PhraseItem usual = new PhraseItem();
PhraseItem filterPhrase = new PhraseItem(new String[] { "bloody", "expensive" });
WordItem filterWord = new WordItem("silly");
filterPhrase.setFilter(true);
filterWord.setFilter(true);
root.addItem(recall);
usual.addItem(new WordItem("new"));
usual.addItem(new WordItem("york"));
recall.addItem(usual);
recall.addItem(new WordItem("shoes"));
root.addItem(new WordItem("nike"));
root.addItem(new WordItem("adidas"));
root.addItem(filterPhrase);
recall.addItem(filterWord);
assertEquals("( \"new york\" AND shoes AND silly ) RANK nike RANK adidas RANK \"bloody expensive\"", searcher.marshalQuery(r));
}
Aggregations