Search in sources :

Example 71 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class DummyHighlighter method doHighlighting.

@Override
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
    NamedList fragments = new SimpleOrderedMap();
    fragments.add("dummy", "thing1");
    return fragments;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 72 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TestToleratedUpdateError method testParseMap.

public void testParseMap() {
    // trivial
    SimpleOrderedMap valid = new SimpleOrderedMap<String>();
    valid.add("type", CmdType.ADD.toString());
    valid.add("id", "some id");
    valid.add("message", "some message");
    ToleratedUpdateError in = ToleratedUpdateError.parseMap(valid);
    compare(in, MAP_COPPIER);
    compare(in, METADATA_COPPIER);
    // randomized
    int numIters = atLeast(5000);
    for (int i = 0; i < numIters; i++) {
        valid = new SimpleOrderedMap<String>();
        valid.add("type", ALL_TYPES[TestUtil.nextInt(random(), 0, ALL_TYPES.length - 1)].toString());
        valid.add("id", TestUtil.randomUnicodeString(random()));
        valid.add("message", TestUtil.randomUnicodeString(random()));
        in = ToleratedUpdateError.parseMap(valid);
        compare(in, MAP_COPPIER);
        compare(in, METADATA_COPPIER);
    }
}
Also used : ToleratedUpdateError(org.apache.solr.common.ToleratedUpdateError) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 73 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class CarrotClusteringEngine method clustersToNamedList.

private void clustersToNamedList(List<Cluster> outputClusters, List<NamedList<Object>> parent, boolean outputSubClusters, int maxLabels) {
    for (Cluster outCluster : outputClusters) {
        NamedList<Object> cluster = new SimpleOrderedMap<>();
        parent.add(cluster);
        // Add labels
        List<String> labels = outCluster.getPhrases();
        if (labels.size() > maxLabels) {
            labels = labels.subList(0, maxLabels);
        }
        cluster.add("labels", labels);
        // Add cluster score
        final Double score = outCluster.getScore();
        if (score != null) {
            cluster.add("score", score);
        }
        // Add other topics marker
        if (outCluster.isOtherTopics()) {
            cluster.add("other-topics", outCluster.isOtherTopics());
        }
        // Add documents
        List<Document> docs = outputSubClusters ? outCluster.getDocuments() : outCluster.getAllDocuments();
        List<Object> docList = new ArrayList<>();
        cluster.add("docs", docList);
        for (Document doc : docs) {
            docList.add(doc.getField(SOLR_DOCUMENT_ID));
        }
        // Add subclusters
        if (outputSubClusters && !outCluster.getSubclusters().isEmpty()) {
            List<NamedList<Object>> subclusters = new ArrayList<>();
            cluster.add("clusters", subclusters);
            clustersToNamedList(outCluster.getSubclusters(), subclusters, outputSubClusters, maxLabels);
        }
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) Cluster(org.carrot2.core.Cluster) Document(org.carrot2.core.Document) SolrDocument(org.apache.solr.common.SolrDocument) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 74 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SolrCore method preDecorateResponse.

public static void preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp) {
    // setup response header
    final NamedList<Object> responseHeader = new SimpleOrderedMap<>();
    rsp.addResponseHeader(responseHeader);
    // toLog is a local ref to the same NamedList used by the response
    NamedList<Object> toLog = rsp.getToLog();
    // for back compat, we set these now just in case other code
    // are expecting them during handleRequest
    toLog.add("webapp", req.getContext().get("webapp"));
    toLog.add(PATH, req.getContext().get(PATH));
    final SolrParams params = req.getParams();
    final String lpList = params.get(CommonParams.LOG_PARAMS_LIST);
    if (lpList == null) {
        toLog.add("params", "{" + req.getParamString() + "}");
    } else if (lpList.length() > 0) {
        toLog.add("params", "{" + params.toFilteredSolrParams(Arrays.asList(lpList.split(","))).toString() + "}");
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 75 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SimpleFacets method getFacetFieldCounts.

/**
   * Returns a list of value constraints and the associated facet counts 
   * for each facet field specified in the params.
   *
   * @see FacetParams#FACET_FIELD
   * @see #getFieldMissingCount
   * @see #getFacetTermEnumCounts
   */
@SuppressWarnings("unchecked")
public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError {
    NamedList<Object> res = new SimpleOrderedMap<>();
    String[] facetFs = global.getParams(FacetParams.FACET_FIELD);
    if (null == facetFs) {
        return res;
    }
    // Passing a negative number for FACET_THREADS implies an unlimited number of threads is acceptable.
    // Also, a subtlety of directExecutor is that no matter how many times you "submit" a job, it's really
    // just a method call in that it's run by the calling thread.
    int maxThreads = req.getParams().getInt(FacetParams.FACET_THREADS, 0);
    Executor executor = maxThreads == 0 ? directExecutor : facetExecutor;
    final Semaphore semaphore = new Semaphore((maxThreads <= 0) ? Integer.MAX_VALUE : maxThreads);
    List<Future<NamedList>> futures = new ArrayList<>(facetFs.length);
    if (fdebugParent != null) {
        fdebugParent.putInfoItem("maxThreads", maxThreads);
    }
    try {
        //Loop over fields; submit to executor, keeping the future
        for (String f : facetFs) {
            if (fdebugParent != null) {
                fdebug = new FacetDebugInfo();
                fdebugParent.addChild(fdebug);
            }
            final ParsedParams parsed = parseParams(FacetParams.FACET_FIELD, f);
            final SolrParams localParams = parsed.localParams;
            final String termList = localParams == null ? null : localParams.get(CommonParams.TERMS);
            final String key = parsed.key;
            final String facetValue = parsed.facetValue;
            Callable<NamedList> callable = () -> {
                try {
                    NamedList<Object> result = new SimpleOrderedMap<>();
                    if (termList != null) {
                        List<String> terms = StrUtils.splitSmart(termList, ",", true);
                        result.add(key, getListedTermCounts(facetValue, parsed, terms));
                    } else {
                        result.add(key, getTermCounts(facetValue, parsed));
                    }
                    return result;
                } catch (SolrException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SolrException(ErrorCode.SERVER_ERROR, "Exception during facet.field: " + facetValue, e);
                } finally {
                    semaphore.release();
                }
            };
            RunnableFuture<NamedList> runnableFuture = new FutureTask<>(callable);
            //may block and/or interrupt
            semaphore.acquire();
            //releases semaphore when done
            executor.execute(runnableFuture);
            futures.add(runnableFuture);
        }
        //Loop over futures to get the values. The order is the same as facetFs but shouldn't matter.
        for (Future<NamedList> future : futures) {
            res.addAll(future.get());
        }
        assert semaphore.availablePermits() >= maxThreads;
    } catch (InterruptedException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error while processing facet fields: InterruptedException", e);
    } catch (ExecutionException ee) {
        //unwrap
        Throwable e = ee.getCause();
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error while processing facet fields: " + e.toString(), e);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) FacetDebugInfo(org.apache.solr.search.facet.FacetDebugInfo) Executor(java.util.concurrent.Executor) FutureTask(java.util.concurrent.FutureTask) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException) NamedList(org.apache.solr.common.util.NamedList) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) RunnableFuture(java.util.concurrent.RunnableFuture) RequiredSolrParams(org.apache.solr.common.params.RequiredSolrParams) SolrParams(org.apache.solr.common.params.SolrParams)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)131 NamedList (org.apache.solr.common.util.NamedList)69 ArrayList (java.util.ArrayList)36 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)27 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 IOException (java.io.IOException)19 List (java.util.List)19 HashMap (java.util.HashMap)18 SolrParams (org.apache.solr.common.params.SolrParams)16 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)16 SchemaField (org.apache.solr.schema.SchemaField)16 FieldType (org.apache.solr.schema.FieldType)14 BytesRef (org.apache.lucene.util.BytesRef)13 Test (org.junit.Test)13 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 SolrDocumentList (org.apache.solr.common.SolrDocumentList)11 HashSet (java.util.HashSet)10 SolrCore (org.apache.solr.core.SolrCore)10 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)9