Search in sources :

Example 1 with QueryTree

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);
}
Also used : PhraseItem(com.yahoo.prelude.query.PhraseItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) QueryTree(com.yahoo.search.query.QueryTree)

Example 2 with QueryTree

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));
}
Also used : AnyParser(com.yahoo.prelude.query.parser.AnyParser) QueryTree(com.yahoo.search.query.QueryTree) Result(com.yahoo.search.Result)

Example 3 with QueryTree

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);
}
Also used : Language(com.yahoo.language.Language) QueryTree(com.yahoo.search.query.QueryTree)

Example 4 with QueryTree

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)
}
Also used : QueryTree(com.yahoo.search.query.QueryTree)

Example 5 with QueryTree

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));
}
Also used : QueryTree(com.yahoo.search.query.QueryTree)

Aggregations

QueryTree (com.yahoo.search.query.QueryTree)26 Test (org.junit.Test)13 AndItem (com.yahoo.prelude.query.AndItem)7 PhraseItem (com.yahoo.prelude.query.PhraseItem)7 WordItem (com.yahoo.prelude.query.WordItem)7 IndexedItem (com.yahoo.prelude.query.IndexedItem)6 Item (com.yahoo.prelude.query.Item)6 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)6 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)5 RegExpItem (com.yahoo.prelude.query.RegExpItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 SuffixItem (com.yahoo.prelude.query.SuffixItem)5 WordAlternativesItem (com.yahoo.prelude.query.WordAlternativesItem)5 Parsable (com.yahoo.search.query.parser.Parsable)3 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)3 IndexFacts (com.yahoo.prelude.IndexFacts)2 IndexModel (com.yahoo.prelude.IndexModel)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 RankItem (com.yahoo.prelude.query.RankItem)2