Search in sources :

Example 61 with WordItem

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

the class LiteralPhraseProduction method produce.

public void produce(RuleEvaluation e, int offset) {
    PhraseItem newPhrase = new PhraseItem();
    newPhrase.setIndexName(getLabel());
    for (String term : terms) newPhrase.addItem(new WordItem(term));
    if (replacing) {
        Match matched = e.getNonreferencedMatch(0);
        insertMatch(e, matched, newPhrase, offset);
    } else {
        newPhrase.setWeight(getWeight());
        if (e.getTraceLevel() >= 6)
            e.trace(6, "Adding '" + newPhrase + "'");
        e.addItem(newPhrase, getTermType());
    }
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Match(com.yahoo.prelude.semantics.engine.Match)

Example 62 with WordItem

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

the class YqlParser method instantiatePhraseSegmentItem.

@NonNull
private Item instantiatePhraseSegmentItem(String field, OperatorNode<ExpressionOperator> ast, boolean forcePhrase) {
    Substring origin = getOrigin(ast);
    Boolean stem = getAnnotation(ast, STEM, Boolean.class, Boolean.TRUE, STEM_DESCRIPTION);
    Boolean andSegmenting = getAnnotation(ast, AND_SEGMENTING, Boolean.class, Boolean.FALSE, "setting for whether to force using AND for segments on and off");
    SegmentItem phrase;
    List<String> words = null;
    if (forcePhrase || !andSegmenting) {
        phrase = new PhraseSegmentItem(origin.getValue(), origin.getValue(), true, !stem, origin);
    } else {
        phrase = new AndSegmentItem(origin.getValue(), true, !stem);
    }
    phrase.setIndexName(field);
    if (resegment && getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION)) {
        words = segmenter.segment(origin.getValue(), currentlyParsing.getLanguage());
    }
    if (words != null && words.size() > 0) {
        for (String word : words) {
            phrase.addItem(new WordItem(word, field, true));
        }
    } else {
        for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
            phrase.addItem(instantiateWordItem(field, word, phrase.getClass(), SegmentWhen.NEVER));
        }
    }
    if (phrase instanceof TaggableItem) {
        leafStyleSettings(ast, (TaggableItem) phrase);
    }
    phrase.lock();
    return phrase;
}
Also used : Substring(com.yahoo.prelude.query.Substring) TaggableItem(com.yahoo.prelude.query.TaggableItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) List(java.util.List) ArrayList(java.util.ArrayList) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 63 with WordItem

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

the class YqlParser method resegment.

@NonNull
private TaggableItem resegment(String field, OperatorNode<ExpressionOperator> ast, String wordData, boolean fromQuery, Class<?> parent, Language language) {
    String toSegment = wordData;
    Substring s = getOrigin(ast);
    Language usedLanguage = language == null ? currentlyParsing.getLanguage() : language;
    if (s != null) {
        toSegment = s.getValue();
    }
    List<String> words = segmenter.segment(toSegment, usedLanguage);
    TaggableItem wordItem;
    if (words.size() == 0) {
        wordItem = new WordItem(wordData, fromQuery);
    } else if (words.size() == 1 || !phraseArgumentSupported(parent)) {
        wordItem = new WordItem(words.get(0), fromQuery);
    } else {
        wordItem = new PhraseSegmentItem(toSegment, fromQuery, false);
        ((PhraseSegmentItem) wordItem).setIndexName(field);
        for (String w : words) {
            WordItem segment = new WordItem(w, fromQuery);
            prepareWord(field, ast, fromQuery, segment);
            ((PhraseSegmentItem) wordItem).addItem(segment);
        }
        ((PhraseSegmentItem) wordItem).lock();
    }
    return wordItem;
}
Also used : Substring(com.yahoo.prelude.query.Substring) TaggableItem(com.yahoo.prelude.query.TaggableItem) Language(com.yahoo.language.Language) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 64 with WordItem

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

the class QueryTestCase method testEncodeQueryPacketWithLabelsConnectivityAndSignificance.

@Test
public void testEncodeQueryPacketWithLabelsConnectivityAndSignificance() {
    Query query = new Query();
    AndItem and = new AndItem();
    WeightedSetItem taggable1 = new WeightedSetItem("field1");
    taggable1.setLabel("foo");
    WeightedSetItem taggable2 = new WeightedSetItem("field2");
    taggable1.setLabel("bar");
    and.addItem(taggable1);
    and.addItem(taggable2);
    WordItem word1 = new WordItem("word1", "field3");
    word1.setSignificance(0.37);
    WordItem word2 = new WordItem("word1", "field3");
    word2.setSignificance(0.81);
    word2.setConnectivity(word1, 0.15);
    and.addItem(word1);
    and.addItem(word2);
    query.getModel().getQueryTree().setRoot(and);
    query.prepare();
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { 0, 0, 1, 16, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, 6, 0, 10, ignored, ignored, ignored, ignored, 0, 0, 0x40, 0x03, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 1, 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 5, 0, 0, 0, 18, 'v', 'e', 's', 'p', 'a', 46, 'l', 'a', 'b', 'e', 'l', 46, 'b', 'a', 'r', 46, 'i', 'd', 0, 0, 0, 1, '1', 0, 0, 0, 22, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 'c', 'o', 'n', 'n', 'e', 'x', 'i', 't', 'y', 0, 0, 0, 1, '3', 0, 0, 0, 22, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 'c', 'o', 'n', 'n', 'e', 'x', 'i', 't', 'y', 0, 0, 0, 4, '0', 46, '1', '5', 0, 0, 0, 25, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '3', 46, 's', 'i', 'g', 'n', 'i', 'f', 'i', 'c', 'a', 'n', 'c', 'e', 0, 0, 0, 4, '0', 46, '3', '7', 0, 0, 0, 25, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 's', 'i', 'g', 'n', 'i', 'f', 'i', 'c', 'a', 'n', 'c', 'e', 0, 0, 0, 4, '0', 46, '8', '1', 0, 0, 0, 5, 0, 0, 0, '4', 1, 4, 79, 1, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 79, 2, 0, 6, 'f', 'i', 'e', 'l', 'd', '2', 68, 3, 6, 'f', 'i', 'e', 'l', 'd', '3', 5, 'w', 'o', 'r', 'd', '1', 68, 4, 6, 'f', 'i', 'e', 'l', 'd', '3', 5, 'w', 'o', 'r', 'd', 49 };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 65 with WordItem

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

the class QueryTestCase method testPhraseEqualsPhraseWithPhraseSegment.

@Test
public void testPhraseEqualsPhraseWithPhraseSegment() throws BufferTooSmallException {
    Query query = new Query();
    PhraseItem p = new PhraseItem();
    PhraseSegmentItem ps = new PhraseSegmentItem("a b", false, false);
    ps.addItem(new WordItem("a"));
    ps.addItem(new WordItem("b"));
    p.addItem(ps);
    query.getModel().getQueryTree().setRoot(p);
    query.setTimeout(0);
    QueryPacket queryPacket = QueryPacket.create(query);
    ByteBuffer buffer1 = ByteBuffer.allocate(1024);
    queryPacket.encode(buffer1, 0);
    query = new Query();
    p = new PhraseItem();
    p.addItem(new WordItem("a"));
    p.addItem(new WordItem("b"));
    query.getModel().getQueryTree().setRoot(p);
    query.setTimeout(0);
    queryPacket = QueryPacket.create(query);
    assertNotNull(queryPacket);
    ByteBuffer buffer2 = ByteBuffer.allocate(1024);
    queryPacket.encode(buffer2, 0);
    byte[] encoded1 = new byte[buffer1.position()];
    buffer1.rewind();
    buffer1.get(encoded1);
    byte[] encoded2 = new byte[buffer2.position()];
    buffer2.rewind();
    buffer2.get(encoded2);
    assertEqualArrays(encoded2, encoded1);
}
Also used : Query(com.yahoo.search.Query) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ByteBuffer(java.nio.ByteBuffer) PhraseItem(com.yahoo.prelude.query.PhraseItem) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Aggregations

WordItem (com.yahoo.prelude.query.WordItem)93 Test (org.junit.Test)76 AndItem (com.yahoo.prelude.query.AndItem)45 PhraseItem (com.yahoo.prelude.query.PhraseItem)31 Query (com.yahoo.search.Query)25 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)20 CompositeItem (com.yahoo.prelude.query.CompositeItem)18 Item (com.yahoo.prelude.query.Item)17 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)16 NotItem (com.yahoo.prelude.query.NotItem)16 OrItem (com.yahoo.prelude.query.OrItem)13 ByteBuffer (java.nio.ByteBuffer)11 PrefixItem (com.yahoo.prelude.query.PrefixItem)10 SubstringItem (com.yahoo.prelude.query.SubstringItem)10 SuffixItem (com.yahoo.prelude.query.SuffixItem)10 Execution (com.yahoo.search.searchchain.Execution)10 RankItem (com.yahoo.prelude.query.RankItem)9 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)9 IntItem (com.yahoo.prelude.query.IntItem)8 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)7