Search in sources :

Example 21 with Index

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

the class NormalizingSearcher method normalizeWord.

private void normalizeWord(Language language, IndexFacts.Session indexFacts, TermItem term, ListIterator<Item> i) {
    if (!(term instanceof WordItem))
        return;
    if (!term.isNormalizable())
        return;
    Index index = indexFacts.getIndex(term.getIndexName());
    if (index.isAttribute())
        return;
    if (!index.getNormalize())
        return;
    WordItem word = (WordItem) term;
    String accentDropped = linguistics.getTransformer().accentDrop(word.getWord(), language);
    if (accentDropped.length() == 0)
        i.remove();
    else
        word.setWord(accentDropped);
}
Also used : Index(com.yahoo.prelude.Index)

Example 22 with Index

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

the class NGramSearcher method recombineNGrams.

private void recombineNGrams(Iterator<Hit> hits, IndexFacts.Session session) {
    while (hits.hasNext()) {
        Hit hit = hits.next();
        if (hit.isMeta())
            continue;
        Object sddocname = hit.getField(Hit.SDDOCNAME_FIELD);
        if (sddocname == null)
            return;
        for (String fieldName : hit.fieldKeys()) {
            Index index = session.getIndex(fieldName, sddocname.toString());
            if (index.isNGram() && (index.getHighlightSummary() || index.getDynamicSummary())) {
                hit.setField(fieldName, recombineNGramsField(hit.getField(fieldName), index.getGramSize()));
            }
        }
    }
}
Also used : Hit(com.yahoo.search.result.Hit) Index(com.yahoo.prelude.Index) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString)

Example 23 with Index

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

the class NGramSearcher method rewriteToNGramMatching.

private boolean rewriteToNGramMatching(Item item, int indexInParent, IndexFacts.Session indexFacts, Query query) {
    boolean rewritten = false;
    if (item instanceof SegmentItem) {
        // handle CJK segmented terms which should be grams instead
        SegmentItem segments = (SegmentItem) item;
        Index index = indexFacts.getIndex(segments.getIndexName());
        if (index.isNGram()) {
            Item grams = splitToGrams(segments, toLowerCase(segments.getRawWord()), index.getGramSize(), query);
            replaceItemByGrams(item, grams, indexInParent);
            rewritten = true;
        }
    } else if (item instanceof CompositeItem) {
        CompositeItem composite = (CompositeItem) item;
        for (int i = 0; i < composite.getItemCount(); i++) rewritten = rewriteToNGramMatching(composite.getItem(i), i, indexFacts, query) || rewritten;
    } else if (item instanceof TermItem) {
        TermItem term = (TermItem) item;
        Index index = indexFacts.getIndex(term.getIndexName());
        if (index.isNGram()) {
            Item grams = splitToGrams(term, term.stringValue(), index.getGramSize(), query);
            replaceItemByGrams(item, grams, indexInParent);
            rewritten = true;
        }
    }
    return rewritten;
}
Also used : Index(com.yahoo.prelude.Index)

Example 24 with Index

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

the class QueryCombinator method addAndItems.

private void addAndItems(Query query, Iterable<QueryPart> pieces, Execution.Context context) {
    IndexFacts indexFacts = context.getIndexFacts();
    IndexFacts.Session session = indexFacts.newSession(query);
    Set<String> usedSources = new HashSet<>(session.documentTypes());
    Language language = query.getModel().getParsingLanguage();
    for (QueryPart part : pieces) {
        String defaultIndex;
        Item item = null;
        Index index = session.getIndex(part.defaultIndex);
        if (index == Index.nullIndex) {
            defaultIndex = null;
        } else {
            defaultIndex = part.defaultIndex;
        }
        try {
            CustomParser parser = (CustomParser) ParserFactory.newInstance(query.getModel().getType(), ParserEnvironment.fromExecutionContext(context));
            item = parser.parse(part.query, null, language, usedSources, indexFacts, defaultIndex);
        } catch (RuntimeException e) {
            String err = Exceptions.toMessageString(e);
            query.trace("Query parser threw an exception: " + err, true, 1);
            getLogger().log(LogLevel.WARNING, "Query parser threw exception searcher QueryCombinator for " + query.getHttpRequest().toString() + ", query part " + part.query + ": " + err);
        }
        if (item == null) {
            continue;
        }
        if (defaultIndex == null) {
            assignDefaultIndex(item, part.defaultIndex);
        }
        addAndItem(query.getModel().getQueryTree(), item);
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IndexFacts(com.yahoo.prelude.IndexFacts) Language(com.yahoo.language.Language) Index(com.yahoo.prelude.Index) CustomParser(com.yahoo.prelude.query.parser.CustomParser) HashSet(java.util.HashSet)

Example 25 with Index

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

the class ValidatePredicateSearcherTestCase method doSearch.

private static Result doSearch(ValidatePredicateSearcher searcher, String yqlQuery, String command) {
    QueryTree queryTree = new YqlParser(new ParserEnvironment()).parse(new Parsable().setQuery(yqlQuery));
    Query query = new Query();
    query.getModel().getQueryTree().setRoot(queryTree.getRoot());
    TreeMap<String, List<String>> masterClusters = new TreeMap<>();
    masterClusters.put("cluster", Arrays.asList("document"));
    SearchDefinition searchDefinition = new SearchDefinition("document");
    Index index = new Index("predicate_field");
    index.addCommand(command);
    searchDefinition.addIndex(index);
    Map<String, SearchDefinition> searchDefinitionMap = new HashMap<>();
    searchDefinitionMap.put("document", searchDefinition);
    IndexFacts indexFacts = new IndexFacts(new IndexModel(masterClusters, searchDefinitionMap, searchDefinition));
    Execution.Context context = new Execution.Context(null, indexFacts, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics());
    return new Execution(searcher, context).search(query);
}
Also used : Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) Parsable(com.yahoo.search.query.parser.Parsable) Index(com.yahoo.prelude.Index) IndexModel(com.yahoo.prelude.IndexModel) SearchDefinition(com.yahoo.prelude.SearchDefinition) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) YqlParser(com.yahoo.search.yql.YqlParser) Execution(com.yahoo.search.searchchain.Execution) QueryTree(com.yahoo.search.query.QueryTree) RendererRegistry(com.yahoo.search.rendering.RendererRegistry) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment)

Aggregations

Index (com.yahoo.prelude.Index)36 IndexFacts (com.yahoo.prelude.IndexFacts)23 Test (org.junit.Test)13 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)7 Query (com.yahoo.search.Query)6 SearchDefinition (com.yahoo.prelude.SearchDefinition)5 Token (com.yahoo.prelude.query.parser.Token)5 Tokenizer (com.yahoo.prelude.query.parser.Tokenizer)5 Execution (com.yahoo.search.searchchain.Execution)4 JSONString (com.yahoo.prelude.hitfield.JSONString)2 XMLString (com.yahoo.prelude.hitfield.XMLString)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 Hit (com.yahoo.search.result.Hit)2 List (java.util.List)2 Before (org.junit.Before)2 Chain (com.yahoo.component.chain.Chain)1 Language (com.yahoo.language.Language)1 StemMode (com.yahoo.language.process.StemMode)1 IndexModel (com.yahoo.prelude.IndexModel)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1