Search in sources :

Example 1 with IntentModel

use of com.yahoo.search.intent.model.IntentModel in project vespa by vespa-engine.

the class PageTemplateSearcher method addSources.

/**
 * Sets query.getModel().getSources() to the right value and add source parameters specified in templates
 */
private void addSources(List<PageElement> pages, Query query) {
    // Determine all wanted sources
    Set<Source> pageSources = new HashSet<>();
    for (PageElement page : pages) pageSources.addAll(((PageTemplate) page).getSources());
    addErrorIfSameSourceMultipleTimes(pages, pageSources, query);
    if (query.getModel().getSources().size() > 0) {
        // Add properties if the source list is set explicitly, but do not modify otherwise
        addParametersForIncludedSources(pageSources, query);
        return;
    }
    if (pageSources.contains(Source.any)) {
        IntentModel intentModel = IntentModel.getFrom(query);
        if (intentModel != null) {
            query.getModel().getSources().addAll(intentModel.getSourceNames());
            addPageTemplateSources(pageSources, query);
        }
    // otherwise leave empty to search all
    } else {
        // Let the page templates decide
        addPageTemplateSources(pageSources, query);
    }
}
Also used : IntentModel(com.yahoo.search.intent.model.IntentModel) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Source(com.yahoo.search.pagetemplates.model.Source)

Example 2 with IntentModel

use of com.yahoo.search.intent.model.IntentModel in project vespa by vespa-engine.

the class RewriterUtils method getSpellCorrected.

/**
 * Retrieve spell corrected query with highest score from QLAS
 *
 * @param query Query object from the searcher
 * @param qss_rw Whether to consider qss_rw modification
 * @param qss_sugg Whether ot consider qss_sugg modification
 * @return Spell corrected query or null if not found
 */
public static String getSpellCorrected(Query query, boolean qss_rw, boolean qss_sugg) throws RuntimeException {
    log(utilsLogger, query, "Retrieving spell corrected query");
    // Retrieve Intent Model
    IntentModel intentModel = IntentModel.getFrom(query);
    if (intentModel == null) {
        error(utilsLogger, query, "Unable to retrieve intent model");
        throw new RuntimeException("Not able to retrieve intent model");
    }
    double max_score = 0;
    String spellCorrected = null;
    // query with highest score
    for (InterpretationNode interpretationNode : intentModel.children()) {
        Modification modification = interpretationNode.getInterpretation().getModification();
        Annotations annotations = modification.getAnnotation();
        Double score = annotations.getDouble("score");
        // Check if it's higher than the max score
        if (score != null && score > max_score) {
            Boolean isQSSRewrite = annotations.getBoolean("qss_rw");
            Boolean isQSSSuggest = annotations.getBoolean("qss_sugg");
            // Check if it's qss_rw or qss_sugg
            if ((qss_rw && isQSSRewrite != null && isQSSRewrite) || (qss_sugg && isQSSSuggest != null && isQSSSuggest)) {
                max_score = score;
                spellCorrected = modification.getText();
            }
        }
    }
    if (spellCorrected != null) {
        log(utilsLogger, query, "Successfully retrieved spell corrected query: " + spellCorrected);
    } else {
        log(utilsLogger, query, "No spell corrected query is retrieved");
    }
    return spellCorrected;
}
Also used : Modification(com.yahoo.text.interpretation.Modification) IntentModel(com.yahoo.search.intent.model.IntentModel) Annotations(com.yahoo.text.interpretation.Annotations) InterpretationNode(com.yahoo.search.intent.model.InterpretationNode)

Aggregations

IntentModel (com.yahoo.search.intent.model.IntentModel)2 InterpretationNode (com.yahoo.search.intent.model.InterpretationNode)1 PageElement (com.yahoo.search.pagetemplates.model.PageElement)1 Source (com.yahoo.search.pagetemplates.model.Source)1 Annotations (com.yahoo.text.interpretation.Annotations)1 Modification (com.yahoo.text.interpretation.Modification)1