use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class DumpRequestHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
// Show params
rsp.add("params", req.getParams().toNamedList());
String[] parts = req.getParams().getParams("urlTemplateValues");
if (parts != null && parts.length > 0) {
Map map = new LinkedHashMap<>();
rsp.getValues().add("urlTemplateValues", map);
for (String part : parts) {
map.put(part, req.getPathTemplateValues().get(part));
}
}
String[] returnParams = req.getParams().getParams("param");
if (returnParams != null) {
NamedList params = (NamedList) rsp.getValues().get("params");
for (String returnParam : returnParams) {
String[] vals = req.getParams().getParams(returnParam);
if (vals != null) {
if (vals.length == 1) {
params.add(returnParam, vals[0]);
} else {
params.add(returnParam, vals);
}
}
}
}
if (req.getParams().getBool("getdefaults", false)) {
NamedList def = (NamedList) initArgs.get(PluginInfo.DEFAULTS);
rsp.add("getdefaults", def);
}
if (req.getParams().getBool("initArgs", false)) {
rsp.add("initArgs", initArgs);
}
// Write the streams...
if (req.getContentStreams() != null) {
ArrayList<NamedList<Object>> streams = new ArrayList<>();
// Cycle through each stream
for (ContentStream content : req.getContentStreams()) {
NamedList<Object> stream = new SimpleOrderedMap<>();
stream.add(NAME, content.getName());
stream.add("sourceInfo", content.getSourceInfo());
stream.add("size", content.getSize());
stream.add("contentType", content.getContentType());
Reader reader = content.getReader();
try {
stream.add("stream", IOUtils.toString(reader));
} finally {
reader.close();
}
streams.add(stream);
}
rsp.add("streams", streams);
}
rsp.add("context", req.getContext());
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class SuggestComponent method toNamedList.
/** Convert {@link SuggesterResult} to NamedList for constructing responses */
private void toNamedList(SuggesterResult suggesterResult, Map<String, SimpleOrderedMap<NamedList<Object>>> resultObj) {
for (String suggesterName : suggesterResult.getSuggesterNames()) {
SimpleOrderedMap<NamedList<Object>> results = new SimpleOrderedMap<>();
for (String token : suggesterResult.getTokens(suggesterName)) {
SimpleOrderedMap<Object> suggestionBody = new SimpleOrderedMap<>();
List<LookupResult> lookupResults = suggesterResult.getLookupResult(suggesterName, token);
suggestionBody.add(SuggesterResultLabels.SUGGESTION_NUM_FOUND, lookupResults.size());
List<SimpleOrderedMap<Object>> suggestEntriesNamedList = new ArrayList<>();
for (LookupResult lookupResult : lookupResults) {
String suggestionString = lookupResult.key.toString();
long weight = lookupResult.value;
String payload = (lookupResult.payload != null) ? lookupResult.payload.utf8ToString() : "";
SimpleOrderedMap<Object> suggestEntryNamedList = new SimpleOrderedMap<>();
suggestEntryNamedList.add(SuggesterResultLabels.SUGGESTION_TERM, suggestionString);
suggestEntryNamedList.add(SuggesterResultLabels.SUGGESTION_WEIGHT, weight);
suggestEntryNamedList.add(SuggesterResultLabels.SUGGESTION_PAYLOAD, payload);
suggestEntriesNamedList.add(suggestEntryNamedList);
}
suggestionBody.add(SuggesterResultLabels.SUGGESTIONS, suggestEntriesNamedList);
results.add(token, suggestionBody);
}
resultObj.put(suggesterName, results);
}
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class TermsComponent method fetchTerms.
private static void fetchTerms(SolrIndexSearcher indexSearcher, String[] fields, String termList, boolean includeTotalTermFreq, NamedList<Object> result) throws IOException {
String[] splitTerms = termList.split(",");
for (int i = 0; i < splitTerms.length; i++) {
splitTerms[i] = splitTerms[i].trim();
}
// Sort the terms once
Arrays.sort(splitTerms);
IndexReaderContext topReaderContext = indexSearcher.getTopReaderContext();
for (String field : fields) {
FieldType fieldType = indexSearcher.getSchema().getField(field).getType();
// Since splitTerms is already sorted, this array will also be sorted
Term[] terms = new Term[splitTerms.length];
for (int i = 0; i < splitTerms.length; i++) {
terms[i] = new Term(field, fieldType.readableToIndexed(splitTerms[i]));
}
TermContext[] termContexts = new TermContext[terms.length];
collectTermContext(topReaderContext, termContexts, terms);
NamedList<Object> termsMap = new SimpleOrderedMap<>();
for (int i = 0; i < terms.length; i++) {
if (termContexts[i] != null) {
String outTerm = fieldType.indexedToReadable(terms[i].bytes().utf8ToString());
int docFreq = termContexts[i].docFreq();
if (!includeTotalTermFreq) {
termsMap.add(outTerm, docFreq);
} else {
long totalTermFreq = termContexts[i].totalTermFreq();
NamedList<Long> termStats = new SimpleOrderedMap<>();
termStats.add("df", (long) docFreq);
termStats.add("ttf", totalTermFreq);
termsMap.add(outTerm, termStats);
}
}
}
result.add(field, termsMap);
}
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class SimpleFacets method getFacetIntervalCounts.
/**
* Returns a <code>NamedList</code> with each entry having the "key" of the interval as name and the count of docs
* in that interval as value. All intervals added in the request are included in the returned
* <code>NamedList</code> (included those with 0 count), and it's required that the order of the intervals
* is deterministic and equals in all shards of a distributed request, otherwise the collation of results
* will fail.
*
*/
public NamedList<Object> getFacetIntervalCounts() throws IOException, SyntaxError {
NamedList<Object> res = new SimpleOrderedMap<Object>();
String[] fields = global.getParams(FacetParams.FACET_INTERVAL);
if (fields == null || fields.length == 0)
return res;
for (String field : fields) {
final ParsedParams parsed = parseParams(FacetParams.FACET_INTERVAL, field);
String[] intervalStrs = parsed.required.getFieldParams(parsed.facetValue, FacetParams.FACET_INTERVAL_SET);
SchemaField schemaField = searcher.getCore().getLatestSchema().getField(parsed.facetValue);
if (parsed.params.getBool(GroupParams.GROUP_FACET, false)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Interval Faceting can't be used with " + GroupParams.GROUP_FACET);
}
if (schemaField.getType().isPointField() && !schemaField.hasDocValues()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't use interval faceting on a PointField without docValues");
}
SimpleOrderedMap<Integer> fieldResults = new SimpleOrderedMap<Integer>();
res.add(parsed.key, fieldResults);
IntervalFacets intervalFacets = new IntervalFacets(schemaField, searcher, parsed.docs, intervalStrs, parsed.params);
for (FacetInterval interval : intervalFacets) {
fieldResults.add(interval.getKey(), interval.getCount());
}
}
return res;
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class BaseSolrResource method handleException.
/**
* If there is an exception on the SolrResponse:
* <ul>
* <li>error info is added to the SolrResponse;</li>
* <li>the response status code is set to the error code from the exception; and</li>
* <li>the exception message is added to the list of things to be logged.</li>
* </ul>
*/
protected void handleException(Logger log) {
Exception exception = getSolrResponse().getException();
if (null != exception) {
NamedList info = new SimpleOrderedMap();
int code = ResponseUtils.getErrorInfo(exception, info, log);
setStatus(Status.valueOf(code));
getSolrResponse().add("error", info);
String message = (String) info.get("msg");
if (null != message && !message.trim().isEmpty()) {
getSolrResponse().getToLog().add("msg", "{" + message.trim() + "}");
}
}
}
Aggregations