Search in sources :

Example 66 with WordItem

use of com.yahoo.prelude.query.WordItem 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());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 67 with WordItem

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

the class QueryLanguageTestCase method testWordWithIndex.

@Test
public void testWordWithIndex() {
    WordItem w = new WordItem("test");
    w.setIndexName("test.index");
    assertEquals("test.index:test", w.toString());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 68 with WordItem

use of com.yahoo.prelude.query.WordItem 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 69 with WordItem

use of com.yahoo.prelude.query.WordItem 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 70 with WordItem

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

the class PhraseMatcherTestCase method testSingleItemMatching.

@Test
public void testSingleItemMatching() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    matcher.setMatchSingleItems(true);
    List<?> matches = matcher.matchPhrases(new WordItem("aword"));
    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("aword"), i.next());
    assertNull(i.getReplace());
    assertFalse(i.hasNext());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Aggregations

WordItem (com.yahoo.prelude.query.WordItem)93 Test (org.junit.Test)76 AndItem (com.yahoo.prelude.query.AndItem)45 PhraseItem (com.yahoo.prelude.query.PhraseItem)31 Query (com.yahoo.search.Query)25 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)20 CompositeItem (com.yahoo.prelude.query.CompositeItem)18 Item (com.yahoo.prelude.query.Item)17 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)16 NotItem (com.yahoo.prelude.query.NotItem)16 OrItem (com.yahoo.prelude.query.OrItem)13 ByteBuffer (java.nio.ByteBuffer)11 PrefixItem (com.yahoo.prelude.query.PrefixItem)10 SubstringItem (com.yahoo.prelude.query.SubstringItem)10 SuffixItem (com.yahoo.prelude.query.SuffixItem)10 Execution (com.yahoo.search.searchchain.Execution)10 RankItem (com.yahoo.prelude.query.RankItem)9 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)9 IntItem (com.yahoo.prelude.query.IntItem)8 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)7