Search in sources :

Example 6 with SolrSuggester

use of org.apache.solr.spelling.suggest.SolrSuggester in project SearchServices by Alfresco.

the class AsyncBuildSuggestComponent method getStatistics.

@Override
public NamedList<String> getStatistics() {
    NamedList<String> stats = new SimpleOrderedMap<>();
    stats.add("totalSizeInBytes", String.valueOf(ramBytesUsed()));
    for (Map.Entry<String, SuggesterCache> entry : suggesters.entrySet()) {
        SolrSuggester suggester = entry.getValue().get(entry.getKey());
        stats.add(entry.getKey(), suggester.toString());
    }
    return stats;
}
Also used : SolrSuggester(org.apache.solr.spelling.suggest.SolrSuggester) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 7 with SolrSuggester

use of org.apache.solr.spelling.suggest.SolrSuggester in project SearchServices by Alfresco.

the class AsyncBuildSuggestComponent method prepare.

/**
 * Responsible for issuing build and rebload command to the specified {@link SolrSuggester}
 */
@Override
public void prepare(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();
    LOG.debug("SuggestComponent prepare with : " + params);
    if (!params.getBool(COMPONENT_NAME, false)) {
        return;
    }
    boolean buildAll = params.getBool(SUGGEST_BUILD_ALL, false);
    boolean reloadAll = params.getBool(SUGGEST_RELOAD_ALL, false);
    final Collection<SolrSuggester> querysuggesters;
    if (buildAll || reloadAll) {
        Collection<SuggesterCache> suggesterCaches = suggesters.values();
        querysuggesters = new ArrayList<SolrSuggester>(suggesterCaches.size());
        for (SuggesterCache cache : suggesterCaches) {
            querysuggesters.add(cache.get(ASYNC_CACHE_KEY));
        }
    } else {
        querysuggesters = getSuggesters(params);
    }
    if (params.getBool(SUGGEST_BUILD, false) || buildAll) {
        for (SolrSuggester suggester : querysuggesters) {
            suggester.build(rb.req.getCore(), rb.req.getSearcher());
        }
        rb.rsp.add("command", (!buildAll) ? "build" : "buildAll");
    } else if (params.getBool(SUGGEST_RELOAD, false) || reloadAll) {
        for (SolrSuggester suggester : querysuggesters) {
            reloadSuggester(suggester, rb.req.getCore(), rb.req.getSearcher());
        }
        rb.rsp.add("command", (!reloadAll) ? "reload" : "reloadAll");
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrSuggester(org.apache.solr.spelling.suggest.SolrSuggester)

Example 8 with SolrSuggester

use of org.apache.solr.spelling.suggest.SolrSuggester in project SearchServices by Alfresco.

the class AsyncBuildSuggestComponent method process.

/**
 * Responsible for using the specified suggester to get the suggestions
 * for the query and write the results
 */
@Override
public void process(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();
    LOG.debug("SuggestComponent process with : " + params);
    if (!params.getBool(COMPONENT_NAME, false) || suggesters.isEmpty()) {
        return;
    }
    boolean buildAll = params.getBool(SUGGEST_BUILD_ALL, false);
    boolean reloadAll = params.getBool(SUGGEST_RELOAD_ALL, false);
    Set<SolrSuggester> querySuggesters;
    try {
        querySuggesters = getSuggesters(params);
    } catch (IllegalArgumentException ex) {
        if (!buildAll && !reloadAll) {
            throw ex;
        } else {
            querySuggesters = new HashSet<>();
        }
    }
    String query = params.get(SUGGEST_Q);
    if (query == null) {
        query = rb.getQueryString();
        if (query == null) {
            query = params.get(CommonParams.Q);
        }
    }
    if (query != null) {
        int count = params.getInt(SUGGEST_COUNT, 1);
        boolean highlight = params.getBool(SUGGEST_HIGHLIGHT, false);
        boolean allTermsRequired = params.getBool(SUGGEST_ALL_TERMS_REQUIRED, true);
        String contextFilter = params.get(SUGGEST_CONTEXT_FILTER_QUERY);
        if (contextFilter != null) {
            contextFilter = contextFilter.trim();
            if (contextFilter.length() == 0) {
                contextFilter = null;
            }
        }
        SuggesterOptions options = new SuggesterOptions(new CharsRef(query), count, contextFilter, allTermsRequired, highlight);
        Map<String, SimpleOrderedMap<NamedList<Object>>> namedListResults = new HashMap<>();
        for (SolrSuggester suggester : querySuggesters) {
            SuggesterResult suggesterResult = suggester.getSuggestions(options);
            toNamedList(suggesterResult, namedListResults);
        }
        rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResults);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SuggesterOptions(org.apache.solr.spelling.suggest.SuggesterOptions) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) CharsRef(org.apache.lucene.util.CharsRef) SuggesterResult(org.apache.solr.spelling.suggest.SuggesterResult) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrSuggester(org.apache.solr.spelling.suggest.SolrSuggester) HashSet(java.util.HashSet)

Aggregations

SolrSuggester (org.apache.solr.spelling.suggest.SolrSuggester)8 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 SolrParams (org.apache.solr.common.params.SolrParams)4 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)4 File (java.io.File)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 CharsRef (org.apache.lucene.util.CharsRef)2 NamedList (org.apache.solr.common.util.NamedList)2 SuggesterOptions (org.apache.solr.spelling.suggest.SuggesterOptions)2 SuggesterResult (org.apache.solr.spelling.suggest.SuggesterResult)2 IOException (java.io.IOException)1 SolrException (org.apache.solr.common.SolrException)1 MetricsMap (org.apache.solr.metrics.MetricsMap)1