Search in sources :

Example 51 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class YqlParser method instantiateWordItem.

@NonNull
private Item instantiateWordItem(String field, String rawWord, OperatorNode<ExpressionOperator> ast, Class<?> parent, SegmentWhen segmentPolicy, boolean exactMatch, Language language) {
    String wordData = rawWord;
    if (getAnnotation(ast, NFKC, Boolean.class, Boolean.FALSE, "setting for whether to NFKC normalize input data")) {
        // NOTE: If this is set to FALSE (default), we will still NFKC normalize text data
        // during tokenization/segmentation, as that is always turned on also on the indexing side.
        wordData = normalizer.normalize(wordData);
    }
    boolean fromQuery = getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION);
    boolean prefixMatch = getAnnotation(ast, PREFIX, Boolean.class, Boolean.FALSE, "setting for whether to use prefix match of input data");
    boolean suffixMatch = getAnnotation(ast, SUFFIX, Boolean.class, Boolean.FALSE, "setting for whether to use suffix match of input data");
    boolean substrMatch = getAnnotation(ast, SUBSTRING, Boolean.class, Boolean.FALSE, "setting for whether to use substring match of input data");
    Preconditions.checkArgument((prefixMatch ? 1 : 0) + (substrMatch ? 1 : 0) + (suffixMatch ? 1 : 0) < 2, "Only one of prefix, substring and suffix can be set.");
    @NonNull final TaggableItem wordItem;
    if (exactMatch) {
        wordItem = new ExactStringItem(wordData, fromQuery);
    } else if (prefixMatch) {
        wordItem = new PrefixItem(wordData, fromQuery);
    } else if (suffixMatch) {
        wordItem = new SuffixItem(wordData, fromQuery);
    } else if (substrMatch) {
        wordItem = new SubstringItem(wordData, fromQuery);
    } else {
        switch(segmentPolicy) {
            case NEVER:
                wordItem = new WordItem(wordData, fromQuery);
                break;
            case POSSIBLY:
                if (shouldResegmentWord(field, fromQuery)) {
                    wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
                } else {
                    wordItem = new WordItem(wordData, fromQuery);
                }
                break;
            case ALWAYS:
                wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
                break;
            default:
                throw new IllegalArgumentException("Unexpected segmenting rule: " + segmentPolicy);
        }
    }
    if (wordItem instanceof WordItem) {
        prepareWord(field, ast, fromQuery, (WordItem) wordItem);
    }
    if (// mark the language used, unless it's the default
    language != Language.ENGLISH)
        ((Item) wordItem).setLanguage(language);
    return (Item) leafStyleSettings(ast, wordItem);
}
Also used : SuffixItem(com.yahoo.prelude.query.SuffixItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull) SubstringItem(com.yahoo.prelude.query.SubstringItem) WordItem(com.yahoo.prelude.query.WordItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 52 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class YqlParser method buildTree.

@NonNull
private QueryTree buildTree(OperatorNode<?> filterPart) {
    Preconditions.checkArgument(filterPart.getArguments().length == 2, "Expected 2 arguments to filter, got %s.", filterPart.getArguments().length);
    populateYqlSources(filterPart.<OperatorNode<?>>getArgument(0));
    OperatorNode<ExpressionOperator> filterExpression = filterPart.getArgument(1);
    populateLinguisticsAnnotations(filterExpression);
    Item root = convertExpression(filterExpression);
    connectItems();
    userQuery = null;
    return new QueryTree(root);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) QueryTree(com.yahoo.search.query.QueryTree) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 53 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class YqlParser method ensureNonEmpty.

private Item ensureNonEmpty(OperatorNode<ExpressionOperator> ast) {
    List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
    Preconditions.checkArgument(args.size() == 1, "Expected 1 arguments, got %s.", args.size());
    Item item = convertExpression(args.get(0));
    ToolBox.visit(noEmptyTerms, item);
    return item;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem)

Example 54 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class QueryTestCase method testDeepCopy.

/**
 * Check copy of query trees is a deep copy
 */
@Test
public void testDeepCopy() {
    Item root1 = parseQuery("a and b and (c or d) and e rank f andnot g", null, Query.Type.ADVANCED);
    Item root2 = root1.clone();
    assertTrue("Item.clone() should be a deep copy.", nonIdenticalTrees(root1, root2));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) Test(org.junit.Test)

Example 55 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class RangeQueryOptimizerTestCase method testRangeOptimizingCarriesOverItemAttributesWhenNotOptimized.

@Test
public void testRangeOptimizingCarriesOverItemAttributesWhenNotOptimized() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem = new IntItem(">" + 15, "s");
    intItem.setWeight(500);
    intItem.setFilter(true);
    intItem.setRanked(false);
    root.addItem(intItem);
    assertOptimized("Not optimized", "AND |s:<15;]!500", query);
    IntItem transformedIntItem = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue("Filter was carried over", transformedIntItem.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem.getWeight());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12