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