Search in sources :

Example 21 with PhraseItem

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

the class CompositeItemCondition method doesMatch.

@Override
protected boolean doesMatch(RuleEvaluation e) {
    Choicepoint choicepoint = e.getChoicepoint(this, true);
    choicepoint.updateState();
    boolean matches = e.currentItem().getItem().getParent() instanceof PhraseItem && allSubConditionsMatches(e);
    if (!matches)
        choicepoint.backtrack();
    return matches;
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint) PhraseItem(com.yahoo.prelude.query.PhraseItem)

Example 22 with PhraseItem

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

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

the class ReferencedMatches method toItem.

/**
 * Returns the item to insert from these referenced matches, or null if none
 *
 * @param label the label of the matches
 */
public Item toItem(String label) {
    if (matches.size() == 0)
        return null;
    if (matches.size() == 1)
        return matches.get(0).toItem(label);
    // TODO: Somehow allow AND items instead here
    PhraseItem phrase = new PhraseItem();
    phrase.setIndexName(label);
    for (Iterator<Match> i = matches.iterator(); i.hasNext(); ) {
        phrase.addItem(i.next().toItem(label));
    }
    return phrase;
}
Also used : PhraseItem(com.yahoo.prelude.query.PhraseItem)

Example 24 with PhraseItem

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

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

the class QueryLanguageTestCase method testPhraseWithIndex.

@Test
public void testPhraseWithIndex() {
    PhraseItem p = new PhraseItem();
    p.addItem(new WordItem("part"));
    p.addItem(new WordItem("of"));
    p.addItem(new WordItem("phrase"));
    p.setIndexName("some.index");
    assertEquals("some.index:\"part of phrase\"", p.toString());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Aggregations

PhraseItem (com.yahoo.prelude.query.PhraseItem)33 WordItem (com.yahoo.prelude.query.WordItem)24 Test (org.junit.Test)23 CompositeItem (com.yahoo.prelude.query.CompositeItem)14 AndItem (com.yahoo.prelude.query.AndItem)13 Item (com.yahoo.prelude.query.Item)10 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)9 OrItem (com.yahoo.prelude.query.OrItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 Query (com.yahoo.search.Query)4 IntItem (com.yahoo.prelude.query.IntItem)3 NotItem (com.yahoo.prelude.query.NotItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 TermItem (com.yahoo.prelude.query.TermItem)2 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)2 Searcher (com.yahoo.search.Searcher)2 QueryTree (com.yahoo.search.query.QueryTree)2 Execution (com.yahoo.search.searchchain.Execution)2