Search in sources :

Example 21 with CompositeItem

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

the class CompositeConverter method itemToForm.

@Override
public DispatchForm itemToForm(Item item, ItemIdMapper itemIdMapper) {
    CompositeItem compositeItem = (CompositeItem) item;
    DispatchForm form = new DispatchForm(getFormName(item));
    for (ListIterator<Item> i = compositeItem.getItemIterator(); i.hasNext(); ) {
        form.addChild(i.next());
    }
    ItemInitializer.initializeForm(form, item, itemIdMapper);
    return form;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) CompositeItem(com.yahoo.prelude.query.CompositeItem) DispatchForm(com.yahoo.search.query.textserialize.serializer.DispatchForm)

Example 22 with CompositeItem

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

the class NonPhrasingSearcherTestCase method testNoNonPhrasingIfSuggestOnly.

@Test
public void testNoNonPhrasingIfSuggestOnly() {
    searcher = new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query("?query=void+tudor+vidor+kanoo&suggestonly=true");
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertEquals(4, item.getItemCount());
    assertEquals("void", ((WordItem) item.getItem(0)).getWord());
    assertEquals("tudor", ((WordItem) item.getItem(1)).getWord());
    assertEquals("vidor", ((WordItem) item.getItem(2)).getWord());
    assertEquals("kanoo", ((WordItem) item.getItem(3)).getWord());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) NonPhrasingSearcher(com.yahoo.prelude.querytransform.NonPhrasingSearcher) Test(org.junit.Test)

Example 23 with CompositeItem

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

the class PhrasingSearcherTestCase method testPartialPhrasing.

@Test
public void testPartialPhrasing() {
    Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query("?query=void%20tudor%20vidor%20kanoo");
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertEquals("void", ((WordItem) item.getItem(0)).getWord());
    assertEquals("kanoo", ((WordItem) item.getItem(2)).getWord());
    PhraseItem phrase = (PhraseItem) item.getItem(1);
    assertEquals(2, phrase.getItemCount());
    assertEquals("tudor", phrase.getWordItem(0).getWord());
    assertEquals("vidor", phrase.getWordItem(1).getWord());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 24 with CompositeItem

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

the class InputCheckingSearcher method checkPhrases.

private void checkPhrases(Item queryItem) {
    if (queryItem instanceof PhraseItem) {
        PhraseItem phrase = (PhraseItem) queryItem;
        repeatedConsecutiveTermsInPhraseCheck(phrase);
        repeatedTermsInPhraseCheck(phrase);
    } else if (queryItem instanceof CompositeItem) {
        CompositeItem asComposite = (CompositeItem) queryItem;
        for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
            checkPhrases(i.next());
        }
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) ListIterator(java.util.ListIterator) PhraseItem(com.yahoo.prelude.query.PhraseItem)

Example 25 with CompositeItem

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

the class InputCheckingSearcher method countSingleCharacterUserTerms.

private int countSingleCharacterUserTerms(Item queryItem) {
    if (queryItem instanceof CompositeItem) {
        int sum = 0;
        CompositeItem asComposite = (CompositeItem) queryItem;
        for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
            sum += countSingleCharacterUserTerms(i.next());
        }
        return sum;
    } else if (queryItem instanceof WordItem) {
        WordItem word = (WordItem) queryItem;
        return (word.isFromQuery() && word.stringValue().length() == 1) ? 1 : 0;
    } else {
        return 0;
    }
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) WordItem(com.yahoo.prelude.query.WordItem)

Aggregations

CompositeItem (com.yahoo.prelude.query.CompositeItem)25 AndItem (com.yahoo.prelude.query.AndItem)13 Test (org.junit.Test)13 Item (com.yahoo.prelude.query.Item)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)10 WordItem (com.yahoo.prelude.query.WordItem)10 Query (com.yahoo.search.Query)10 Execution (com.yahoo.search.searchchain.Execution)9 NotItem (com.yahoo.prelude.query.NotItem)6 NullItem (com.yahoo.prelude.query.NullItem)6 OrItem (com.yahoo.prelude.query.OrItem)6 EquivItem (com.yahoo.prelude.query.EquivItem)5 NearItem (com.yahoo.prelude.query.NearItem)5 RankItem (com.yahoo.prelude.query.RankItem)5 SimpleIndexedItem (com.yahoo.prelude.query.SimpleIndexedItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)4 Searcher (com.yahoo.search.Searcher)4 NonPhrasingSearcher (com.yahoo.prelude.querytransform.NonPhrasingSearcher)3 TermItem (com.yahoo.prelude.query.TermItem)2