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;
}
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);
}
}
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);
}
}
}
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() + "}");
}
}
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;
}
Aggregations