Search in sources :

Example 11 with AndItem

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

the class CollapsePhraseSearcherTestCase method testNegative3.

@Test
public void testNegative3() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    CompositeItem embedded = new AndItem();
    embedded.addItem(new WordItem("bcd"));
    CompositeItem phrase = new PhraseItem();
    phrase.addItem(new WordItem("def"));
    phrase.addItem(new WordItem("ghi"));
    embedded.addItem(phrase);
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a (AND bcd \"def ghi\") e", transformQuery(root));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 12 with AndItem

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

the class CollapsePhraseSearcherTestCase method testPositive1.

@Test
public void testPositive1() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    PhraseItem embedded = new PhraseItem();
    embedded.addItem(new WordItem("bcd"));
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a bcd e", transformQuery(root));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 13 with AndItem

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

the class PhraseMatcherTestCase method testPhraseMatchingCaseInsensitive.

@Test
public void testPhraseMatchingCaseInsensitive() {
    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 = "thIs";
    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 = "tEst";
    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(null, 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(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 14 with AndItem

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

the class PhraseMatcherTestCase method testPhraseMatchingWithNumber.

@Test
public void testPhraseMatchingWithNumber() {
    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 IntItem("3"));
    and.addItem(new WordItem("tests"));
    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 IntItem("3"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("tests"), i.next());
    assertEquals(null, i.getReplace());
    assertFalse(i.hasNext());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 15 with AndItem

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

the class PhraseMatcherTestCase method testPhraseMatchingWithPluralIgnore.

@Test
public void testPhraseMatchingWithPluralIgnore() {
    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("thi"));
    and.addItem(new WordItem("is"));
    and.addItem(new WordItem("a"));
    and.addItem(new WordItem("tests"));
    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("thi"), i.next());
    assertEquals("this", 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("tests"), 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)

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