use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class PhraseMatcherTestCase method testSingleItemMatchingWithPluralIgnore.
@Test
public void testSingleItemMatchingWithPluralIgnore() {
PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
matcher.setMatchSingleItems(true);
List<?> matches = matcher.matchPhrases(new WordItem("awords"));
assertNotNull(matches);
assertEquals(1, matches.size());
PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
assertEquals(1, match.getLength());
assertEquals("", match.getData());
assertEquals(null, match.getOwner());
assertEquals(0, match.getStartIndex());
PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
assertEquals(new WordItem("awords"), i.next());
assertEquals("aword", i.getReplace());
assertFalse(i.hasNext());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class QueryCombinatorTestCase method testMultiPart.
public void testMultiPart() {
Query q = new Query("?query=a&query.juhu=b&query.nalle=c");
Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
Set<String> items = new HashSet<>();
items.add("a");
items.add("b");
items.add("c");
e.search(q);
// OK, the problem here is we have no way of knowing whether nalle or
// juhu was added first, since we have passed through HashMap instances
// inside the implementation
AndItem root = (AndItem) q.getModel().getQueryTree().getRoot();
Iterator<?> iterator = root.getItemIterator();
while (iterator.hasNext()) {
WordItem word = (WordItem) iterator.next();
if (items.contains(word.stringValue())) {
items.remove(word.stringValue());
} else {
assertFalse("Got unexpected item in query tree: " + word.stringValue(), true);
}
}
assertEquals("Not all expected items found in query.", 0, items.size());
Set<StringPair> nastierItems = new HashSet<>();
nastierItems.add(new StringPair("", "a"));
nastierItems.add(new StringPair("juhu.22[gnuff]", "b"));
nastierItems.add(new StringPair("gnuff[8].name(\"tralala\")", "c"));
q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]&query.nalle=c&defidx.nalle=gnuff[8].name(%22tralala%22)");
e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
e.search(q);
root = (AndItem) q.getModel().getQueryTree().getRoot();
iterator = root.getItemIterator();
while (iterator.hasNext()) {
WordItem word = (WordItem) iterator.next();
StringPair asPair = new StringPair(word.getIndexName(), word.stringValue());
if (nastierItems.contains(asPair)) {
nastierItems.remove(asPair);
} else {
assertFalse("Got unexpected item in query tree: (" + word.getIndexName() + ", " + word.stringValue() + ")", true);
}
}
assertEquals("Not all expected items found in query.", 0, nastierItems.size());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class QueryTestCase method testSimpleFunctionality.
@Test
public void testSimpleFunctionality() {
Query q = new Query(QueryTestCase.httpEncode("/sdfsd.html?query=this is a simple query&aParameter"));
assertEquals("this is a simple query", q.getModel().getQueryString());
assertNotNull(q.getModel().getQueryTree());
assertNull(q.getModel().getDefaultIndex());
assertEquals("", q.properties().get("aParameter"));
assertNull(q.properties().get("notSetParameter"));
Query query = q;
String body = "a bb. ccc??!";
Linguistics linguistics = new SimpleLinguistics();
AndItem and = new AndItem();
for (Token token : linguistics.getTokenizer().tokenize(body, Language.ENGLISH, StemMode.SHORTEST, true)) {
if (token.isIndexable())
and.addItem(new WordItem(token.getTokenString(), "body"));
}
query.getModel().getQueryTree().setRoot(and);
System.out.println(query);
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_word_item.
@Test
public void serialize_word_item() {
WordItem item = new WordItem("test that \" and \\ works");
item.setIndexName("index\"Name");
WordItem deSerialized = serializeThenParse(item);
assertThat(deSerialized.getWord(), is(item.getWord()));
assertThat(deSerialized.getIndexName(), is(item.getIndexName()));
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_equiv_item.
@Test
public void serialize_equiv_item() throws ParseException {
EquivItem equivItem = new EquivItem();
equivItem.addItem(new WordItem("first"));
EquivItem deSerialized = serializeThenParse(equivItem);
assertThat(deSerialized.getItemCount(), is(1));
}
Aggregations