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;
}
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());
}
}
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;
}
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);
}
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());
}
Aggregations