Search in sources :

Example 36 with AndItem

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

the class PhraseMatcherTestCase method testPhraseMatchingCaseInsensitiveWithPluralIgnore.

@Test
public void testPhraseMatchingCaseInsensitiveWithPluralIgnore() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
    AndItem and = new AndItem();
    and.addItem(new WordItem("noisebefore"));
    final String firstWord = "thI";
    and.addItem(new WordItem(firstWord));
    final String secondWord = "Is";
    and.addItem(new WordItem(secondWord));
    final String thirdWord = "A";
    and.addItem(new WordItem(thirdWord));
    final String fourthWord = "tEsts";
    and.addItem(new WordItem(fourthWord));
    and.addItem(new WordItem("noiseafter"));
    List<?> matches = matcher.matchPhrases(and);
    assertNotNull(matches);
    assertEquals(1, matches.size());
    PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
    assertEquals(4, match.getLength());
    assertEquals("", match.getData());
    assertEquals(and, match.getOwner());
    assertEquals(1, match.getStartIndex());
    PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
    assertEquals(new WordItem(firstWord), i.next());
    assertEquals("this", i.getReplace());
    assertEquals(new WordItem(secondWord), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem(thirdWord), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem(fourthWord), i.next());
    assertEquals("test", i.getReplace());
    assertFalse(i.hasNext());
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 37 with AndItem

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

the class PhraseMatcherTestCase method testPhraseMatching.

@Test
public void testPhraseMatching() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
    AndItem and = new AndItem();
    and.addItem(new WordItem("noisebefore"));
    and.addItem(new WordItem("this"));
    and.addItem(new WordItem("is"));
    and.addItem(new WordItem("a"));
    and.addItem(new WordItem("test"));
    and.addItem(new WordItem("noiseafter"));
    List<?> matches = matcher.matchPhrases(and);
    assertNotNull(matches);
    assertEquals(1, matches.size());
    PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
    assertEquals(4, match.getLength());
    assertEquals("", match.getData());
    assertEquals(and, match.getOwner());
    assertEquals(1, match.getStartIndex());
    PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
    assertEquals(new WordItem("this"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("is"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("a"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("test"), i.next());
    assertEquals(null, i.getReplace());
    assertFalse(i.hasNext());
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 38 with AndItem

use of com.yahoo.prelude.query.AndItem 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());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) HashSet(java.util.HashSet)

Example 39 with AndItem

use of com.yahoo.prelude.query.AndItem 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);
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Linguistics(com.yahoo.language.Linguistics) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) Token(com.yahoo.language.process.Token) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 40 with AndItem

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

the class SerializeItemTestCase method serialize_and_item.

@Test
public void serialize_and_item() throws ParseException {
    AndItem andItem = new AndItem();
    andItem.addItem(new WordItem("first"));
    andItem.addItem(new WordItem("second"));
    AndItem deSerialized = serializeThenParse(andItem);
    assertThat(getWord(deSerialized.getItem(0)), is("first"));
    assertThat(getWord(deSerialized.getItem(1)), is("second"));
    assertThat(deSerialized.getItemCount(), is(2));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Aggregations

AndItem (com.yahoo.prelude.query.AndItem)50 Test (org.junit.Test)39 WordItem (com.yahoo.prelude.query.WordItem)36 Query (com.yahoo.search.Query)24 Item (com.yahoo.prelude.query.Item)13 CompositeItem (com.yahoo.prelude.query.CompositeItem)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)12 OrItem (com.yahoo.prelude.query.OrItem)10 Execution (com.yahoo.search.searchchain.Execution)10 IntItem (com.yahoo.prelude.query.IntItem)9 NotItem (com.yahoo.prelude.query.NotItem)7 RankItem (com.yahoo.prelude.query.RankItem)7 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)5 Searcher (com.yahoo.search.Searcher)5 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)4 Result (com.yahoo.search.Result)4 IndexFacts (com.yahoo.prelude.IndexFacts)3