Search in sources :

Example 11 with PhraseSegmentItem

use of com.yahoo.prelude.query.PhraseSegmentItem 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 12 with PhraseSegmentItem

use of com.yahoo.prelude.query.PhraseSegmentItem 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)

Example 13 with PhraseSegmentItem

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

the class PhraseItemTestCase method testAddItemWithIndex.

@Test
public void testAddItemWithIndex() {
    PhraseItem p = new PhraseItem();
    PhraseSegmentItem pp = new PhraseSegmentItem("", false, false);
    PhraseItem ppp = new PhraseItem();
    pp.addItem(new WordItem("a"));
    pp.addItem(new WordItem("b"));
    ppp.addItem(new WordItem("c"));
    ppp.addItem(new WordItem("d"));
    p.addItem(0, new WordItem("e"));
    p.addItem(0, pp);
    p.addItem(2, new WordItem("f"));
    p.addItem(1, ppp);
    assertEquals("\"'a b' c d e f\"", p.toString());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 14 with PhraseSegmentItem

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

the class NormalizingSearcherTestCase method testPhraseSegmentNormalization.

@Test
public void testPhraseSegmentNormalization() {
    Query query = new Query("/search?query=&search=cluster1&restrict=type1");
    PhraseSegmentItem phraseSegment = new PhraseSegmentItem("default", false, false);
    phraseSegment.addItem(new WordItem("net"));
    query.getModel().getQueryTree().setRoot(phraseSegment);
    assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
    createExecution().search(query);
    assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
}
Also used : Query(com.yahoo.search.Query) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Aggregations

PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)14 WordItem (com.yahoo.prelude.query.WordItem)14 Test (org.junit.Test)10 PhraseItem (com.yahoo.prelude.query.PhraseItem)9 AndItem (com.yahoo.prelude.query.AndItem)5 CompositeItem (com.yahoo.prelude.query.CompositeItem)4 Item (com.yahoo.prelude.query.Item)4 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)3 OrItem (com.yahoo.prelude.query.OrItem)3 SegmentItem (com.yahoo.prelude.query.SegmentItem)3 Query (com.yahoo.search.Query)3 IntItem (com.yahoo.prelude.query.IntItem)2 NotItem (com.yahoo.prelude.query.NotItem)2 PrefixItem (com.yahoo.prelude.query.PrefixItem)2 RankItem (com.yahoo.prelude.query.RankItem)2 Substring (com.yahoo.prelude.query.Substring)2 SubstringItem (com.yahoo.prelude.query.SubstringItem)2 SuffixItem (com.yahoo.prelude.query.SuffixItem)2 TaggableItem (com.yahoo.prelude.query.TaggableItem)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2