Java Code Examples for org.apache.solr.common.util.SimpleOrderedMap#add()
The following examples show how to use
org.apache.solr.common.util.SimpleOrderedMap#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MtasSolrComponentCollection.java From mtas with Apache License 2.0 | 6 votes |
public SimpleOrderedMap<Object> create( ComponentCollection componentCollection, Boolean encode) throws IOException { MtasSolrCollectionResult data = createMtasSolrCollectionResult( componentCollection, encode ? false : true); // Create response SimpleOrderedMap<Object> mtasCollectionResponse = new SimpleOrderedMap<>(); mtasCollectionResponse.add("key", componentCollection.key); if (encode) { mtasCollectionResponse.add("_encoded_data", MtasSolrResultUtil.encode(data)); } else { mtasCollectionResponse.add("data", data); MtasSolrResultUtil.rewrite(mtasCollectionResponse, searchComponent); } return mtasCollectionResponse; }
Example 2
Source File: FacetBucket.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) public SimpleOrderedMap getMergedBucket() { SimpleOrderedMap out = new SimpleOrderedMap( (subs == null ? 0 : subs.size()) + 2 ); if (bucketValue != null) { out.add("val", bucketValue); } out.add("count", count); if (subs != null) { for (Map.Entry<String,FacetMerger> mergerEntry : subs.entrySet()) { FacetMerger subMerger = mergerEntry.getValue(); Object mergedResult = subMerger.getMergedResult(); if (null != mergedResult) { out.add(mergerEntry.getKey(), mergedResult); } } } return out; }
Example 3
Source File: MtasSolrCollectionCache.java From mtas with Apache License 2.0 | 6 votes |
/** * Check. * * @param id the id * @return the simple ordered map * @throws IOException Signals that an I/O exception has occurred. */ public SimpleOrderedMap<Object> check(String id) throws IOException { if (idToVersion.containsKey(id)) { String version = idToVersion.get(id); MtasSolrCollectionCacheItem item = versionToItem.get(version); Date date = new Date(); long now = date.getTime(); if (verify(version, now)) { SimpleOrderedMap<Object> data = new SimpleOrderedMap<>(); data.add("now", now); data.add("id", item.id); data.add("size", item.size); data.add("version", version); data.add("expiration", expirationVersion.get(version)); return data; } else { idToVersion.remove(id); versionToItem.remove(version); expirationVersion.remove(version); return null; } } else { return null; } }
Example 4
Source File: SolrParams.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Convert this to a NamedList of unique keys with either String or String[] values depending on * how many values there are for the parameter. */ public NamedList<Object> toNamedList() { final SimpleOrderedMap<Object> result = new SimpleOrderedMap<>(); for(Iterator<String> it=getParameterNamesIterator(); it.hasNext(); ) { final String name = it.next(); final String [] values = getParams(name); if(values.length==1) { result.add(name,values[0]); } else { // currently no reason not to use the same array result.add(name,values); } } return result; }
Example 5
Source File: FeaturesExtractorManager.java From ltr4l with Apache License 2.0 | 6 votes |
public SimpleOrderedMap<Object> getResult(){ if(future.isDone()){ SimpleOrderedMap<Object> result = new SimpleOrderedMap<Object>(); Reader r = null; try{ r = new FileReader(featuresFile); ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); Map<String, Object> json = mapper.readValue(featuresFile, Map.class); result.add("data", parseData(json)); return result; } catch (IOException e) { throw new RuntimeException(e); } finally{ IOUtils.closeWhileHandlingException(r); } } else return null; }
Example 6
Source File: AsyncBuildSuggestComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** 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); } }
Example 7
Source File: CustomHighlightComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) protected Object convertHighlights(@SuppressWarnings({"rawtypes"})NamedList hl) { @SuppressWarnings({"rawtypes"}) final ArrayList<SimpleOrderedMap> hlMaps = new ArrayList<>(); for (int i=0; i<hl.size(); ++i) { @SuppressWarnings({"rawtypes"}) SimpleOrderedMap hlMap = new SimpleOrderedMap<Object>(); hlMap.add(id_key, hl.getName(i)); hlMap.add(snippets_key, hl.getVal(i)); hlMaps.add(hlMap); } return hlMaps; }
Example 8
Source File: MtasSolrComponentFacet.java From mtas with Apache License 2.0 | 5 votes |
public SimpleOrderedMap<Object> create(ComponentFacet facet, Boolean encode) throws IOException { SimpleOrderedMap<Object> mtasFacetResponse = new SimpleOrderedMap<>(); mtasFacetResponse.add("key", facet.key); HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>(); for (int i = 0; i < facet.baseFields.length; i++) { if (facet.baseFunctionList[i] != null) { for (MtasDataCollector<?, ?> functionDataCollector : facet.baseFunctionList[i] .keySet()) { SubComponentFunction[] tmpSubComponentFunctionList = facet.baseFunctionList[i] .get(functionDataCollector); if (tmpSubComponentFunctionList != null) { HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<>(); for (SubComponentFunction tmpSubComponentFunction : tmpSubComponentFunctionList) { tmpList.put(tmpSubComponentFunction.key, new MtasSolrMtasResult(tmpSubComponentFunction.dataCollector, tmpSubComponentFunction.dataType, tmpSubComponentFunction.statsType, tmpSubComponentFunction.statsItems, null, null)); } functionData.put(functionDataCollector, tmpList); } } } } MtasSolrMtasResult data = new MtasSolrMtasResult(facet.dataCollector, facet.baseDataTypes, facet.baseStatsTypes, facet.baseStatsItems, null, facet.baseSortTypes, facet.baseSortDirections, null, facet.baseNumbers, functionData); if (encode) { mtasFacetResponse.add("_encoded_list", MtasSolrResultUtil.encode(data)); } else { mtasFacetResponse.add("list", data); MtasSolrResultUtil.rewrite(mtasFacetResponse, searchComponent); } return mtasFacetResponse; }
Example 9
Source File: FacetFieldAdapterTest.java From semantic-knowledge-graph with Apache License 2.0 | 5 votes |
@Test public void getMapValue_Title() throws IOException { NodeContext context = new NodeContext(new ParameterSet(null,null,invariants)); FacetFieldAdapter target = new FacetFieldAdapter(context, "title"); SimpleOrderedMap<Object> resultBucket = new SimpleOrderedMap<>(); resultBucket.add("val", "99^testtitle"); SimpleOrderedMap<String> actual = target.getMapValue(resultBucket); Assert.assertEquals("99", actual.get("id")); Assert.assertEquals("testtitle", actual.get("title")); }
Example 10
Source File: AlfrescoLukeRequestHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private static void populateFieldInfo(IndexSchema schema, Map<String, List<String>> typeusemap, Map<String, Object> fields, SchemaField uniqueField, SchemaField f) { FieldType ft = f.getType(); SimpleOrderedMap<Object> field = new SimpleOrderedMap<>(); field.add("type", ft.getTypeName()); field.add("flags", getFieldFlags(f)); if (f.isRequired()) { field.add("required", f.isRequired()); } if (f.getDefaultValue() != null) { field.add("default", f.getDefaultValue()); } if (f == uniqueField) { field.add("uniqueKey", true); } if (ft.getIndexAnalyzer().getPositionIncrementGap(f.getName()) != 0) { field.add("positionIncrementGap", ft.getIndexAnalyzer() .getPositionIncrementGap(f.getName())); } field.add("copyDests", toListOfStringDests(schema.getCopyFieldsList(f.getName()))); field.add("copySources", schema.getCopySources(f.getName())); fields.put(f.getName(), field); List<String> v = typeusemap.get(ft.getTypeName()); if (v == null) { v = new ArrayList<>(); } v.add(f.getName()); typeusemap.put(ft.getTypeName(), v); }
Example 11
Source File: AlfrescoLukeRequestHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private static SimpleOrderedMap<Object> getSimilarityInfo( Similarity similarity) { SimpleOrderedMap<Object> toReturn = new SimpleOrderedMap<>(); if (similarity != null) { toReturn.add("className", similarity.getClass().getName()); toReturn.add("details", similarity.toString()); } return toReturn; }
Example 12
Source File: FacetFieldProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
private SimpleOrderedMap<Object> refineBucket(Object bucketVal, boolean skip, Map<String,Object> facetInfo) throws IOException { SimpleOrderedMap<Object> bucket = new SimpleOrderedMap<>(); FieldType ft = sf.getType(); bucketVal = ft.toNativeType(bucketVal); // refinement info passed in as JSON will cause int->long and float->double bucket.add("val", bucketVal); // fieldQuery currently relies on a string input of the value... String bucketStr = bucketVal instanceof Date ? ((Date)bucketVal).toInstant().toString() : bucketVal.toString(); Query domainQ = ft.getFieldQuery(null, sf, bucketStr); fillBucket(bucket, domainQ, null, skip, facetInfo); return bucket; }
Example 13
Source File: PhrasesIdentificationComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes"}) public NamedList getDetails() { SimpleOrderedMap<Object> out = new SimpleOrderedMap<Object>(); out.add("text", subSequence); out.add("offset_start", getOffsetStart()); out.add("offset_end", getOffsetEnd()); out.add("score", getTotalScore()); out.add("field_scores", fieldScores); return out; }
Example 14
Source File: OverseerSolrResponseTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testException() { NamedList<Object> responseNl = new NamedList<>(); SolrException e = new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Foo"); SimpleOrderedMap<Object> exceptionNl = new SimpleOrderedMap<>(); exceptionNl.add("msg", e.getMessage()); exceptionNl.add("rspCode", e.code()); responseNl.add("exception", exceptionNl); OverseerSolrResponse deserialized = OverseerSolrResponseSerializer.deserialize(OverseerSolrResponseSerializer.serialize(new OverseerSolrResponse(responseNl))); assertNotNull("Expecting an exception", deserialized.getException()); assertEquals("Unexpected exception type in deserialized response", SolrException.class, deserialized.getException().getClass()); assertEquals("Unexpected exception code in deserialized response", e.code(), ((SolrException)deserialized.getException()).code()); assertEquals("Unexpected exception message in deserialized response", e.getMessage(), deserialized.getException().getMessage()); }
Example 15
Source File: FacetFieldAdapterTest.java From semantic-knowledge-graph with Apache License 2.0 | 5 votes |
@Test public void getMapValue_Tags() throws IOException { NodeContext context = new NodeContext(new ParameterSet(null,null,invariants)); FacetFieldAdapter target = new FacetFieldAdapter(context, "tags"); SimpleOrderedMap<Object> resultBucket = new SimpleOrderedMap<>(); resultBucket.add("val", "99^testtitle"); SimpleOrderedMap<String> actual = target.getMapValue(resultBucket); Assert.assertEquals("99", actual.get("id")); Assert.assertEquals("testtitle", actual.get("title")); }
Example 16
Source File: MtasSolrComponentTermvector.java From mtas with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public SimpleOrderedMap<Object> create(ComponentTermVector termVector, Boolean encode) throws IOException { SimpleOrderedMap<Object> mtasTermVectorResponse = new SimpleOrderedMap<>(); mtasTermVectorResponse.add("key", termVector.key); termVector.subComponentFunction.dataCollector.close(); HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>(); HashMap<String, MtasSolrMtasResult> functionDataItem = new HashMap<>(); functionData.put(termVector.subComponentFunction.dataCollector, functionDataItem); if (termVector.functions != null) { for (SubComponentFunction function : termVector.functions) { function.dataCollector.reduceToKeys( termVector.subComponentFunction.dataCollector.getKeyList()); function.dataCollector.close(); functionDataItem.put(function.key, new MtasSolrMtasResult( function.dataCollector, new String[] { function.dataType }, new String[] { function.statsType }, new SortedSet[] { function.statsItems }, new List[] { null }, new String[] { null }, new String[] { null }, new Integer[] { 0 }, new Integer[] { Integer.MAX_VALUE }, null)); } } MtasSolrMtasResult data = new MtasSolrMtasResult( termVector.subComponentFunction.dataCollector, new String[] { termVector.subComponentFunction.dataType }, new String[] { termVector.subComponentFunction.statsType }, new SortedSet[] { termVector.subComponentFunction.statsItems }, new List[] { termVector.distances }, new String[] { termVector.subComponentFunction.sortType }, new String[] { termVector.subComponentFunction.sortDirection }, new Integer[] { 0 }, new Integer[] { termVector.number }, functionData); if (encode) { mtasTermVectorResponse.add("_encoded_list", MtasSolrResultUtil.encode(data)); } else { mtasTermVectorResponse.add("list", data); MtasSolrResultUtil.rewrite(mtasTermVectorResponse, searchComponent); } return mtasTermVectorResponse; }
Example 17
Source File: LukeRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static void getDetailedFieldInfo(SolrQueryRequest req, String field, SimpleOrderedMap<Object> fieldMap) throws IOException { SolrParams params = req.getParams(); final int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT ); TopTermQueue tiq = new TopTermQueue(numTerms + 1); // Something to collect the top N terms in. final CharsRefBuilder spare = new CharsRefBuilder(); Terms terms = MultiTerms.getTerms(req.getSearcher().getIndexReader(), field); if (terms == null) { // field does not exist return; } TermsEnum termsEnum = terms.iterator(); BytesRef text; int[] buckets = new int[HIST_ARRAY_SIZE]; while ((text = termsEnum.next()) != null) { ++tiq.distinctTerms; int freq = termsEnum.docFreq(); // This calculation seems odd, but it gives the same results as it used to. int slot = 32 - Integer.numberOfLeadingZeros(Math.max(0, freq - 1)); buckets[slot] = buckets[slot] + 1; if (numTerms > 0 && freq > tiq.minFreq) { spare.copyUTF8Bytes(text); String t = spare.toString(); tiq.add(new TopTermQueue.TermInfo(new Term(field, t), termsEnum.docFreq())); if (tiq.size() > numTerms) { // if tiq full tiq.pop(); // remove lowest in tiq tiq.minFreq = tiq.getTopTermInfo().docFreq; } } } tiq.histogram.add(buckets); fieldMap.add("distinct", tiq.distinctTerms); // Include top terms fieldMap.add("topTerms", tiq.toNamedList(req.getSearcher().getSchema())); // Add a histogram fieldMap.add("histogram", tiq.histogram.toNamedList()); }
Example 18
Source File: SpellCheckComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) protected NamedList toNamedList(boolean shardRequest, SpellingResult spellingResult, String origQuery, boolean extendedResults) { NamedList result = new NamedList(); Map<Token,LinkedHashMap<String,Integer>> suggestions = spellingResult .getSuggestions(); boolean hasFreqInfo = spellingResult.hasTokenFrequencyInfo(); boolean hasSuggestions = false; boolean hasZeroFrequencyToken = false; for (Map.Entry<Token,LinkedHashMap<String,Integer>> entry : suggestions .entrySet()) { Token inputToken = entry.getKey(); String tokenString = new String(inputToken.buffer(), 0, inputToken .length()); Map<String,Integer> theSuggestions = new LinkedHashMap<>( entry.getValue()); Iterator<String> sugIter = theSuggestions.keySet().iterator(); while (sugIter.hasNext()) { String sug = sugIter.next(); if (sug.equals(tokenString)) { sugIter.remove(); } } if (theSuggestions.size() > 0) { hasSuggestions = true; } if (theSuggestions != null && (theSuggestions.size() > 0 || shardRequest)) { SimpleOrderedMap suggestionList = new SimpleOrderedMap(); suggestionList.add("numFound", theSuggestions.size()); suggestionList.add("startOffset", inputToken.startOffset()); suggestionList.add("endOffset", inputToken.endOffset()); // Logical structure of normal (non-extended) results: // "suggestion":["alt1","alt2"] // // Logical structure of the extended results: // "suggestion":[ // {"word":"alt1","freq":7}, // {"word":"alt2","freq":4} // ] if (extendedResults && hasFreqInfo) { suggestionList.add("origFreq", spellingResult .getTokenFrequency(inputToken)); ArrayList<SimpleOrderedMap> sugs = new ArrayList<>(); suggestionList.add("suggestion", sugs); for (Map.Entry<String,Integer> suggEntry : theSuggestions.entrySet()) { SimpleOrderedMap sugEntry = new SimpleOrderedMap(); sugEntry.add("word", suggEntry.getKey()); sugEntry.add("freq", suggEntry.getValue()); sugs.add(sugEntry); } } else { suggestionList.add("suggestion", theSuggestions.keySet()); } if (hasFreqInfo) { Integer tokenFrequency = spellingResult.getTokenFrequency(inputToken); if (tokenFrequency==null || tokenFrequency == 0) { hasZeroFrequencyToken = true; } } result.add(tokenString, suggestionList); } } return result; }
Example 19
Source File: FeaturesRequestHandler.java From ltr4l with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { SimpleOrderedMap<Object> results = new SimpleOrderedMap<Object>(); String command = req.getParams().required().get("command"); results.add("command", command); if(command.equals("extract")){ Iterable<ContentStream> ite = req.getContentStreams(); if(ite == null){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no queries found"); } else{ handleExtract(req, ite, results); } } else if(command.equals("progress")){ handleProgress(req, results); } else if(command.equals("download")){ long procId = req.getParams().required().getLong("procId"); final boolean delete = req.getParams().getBool("delete", false); SimpleOrderedMap<Object> data = download(procId, delete); results.add("procId", procId); if(data == null){ FeaturesExtractorManager manager = getManager(procId); results.add("done?", manager.isDone()); results.add("progress", manager.getProgress()); results.add("result", "the process still runs..."); } else{ if(delete){ results.add("deleted", "the process has been removed and the procId is no longer valid"); } results.add("result", data); } } else if(command.equals("delete")){ handleDelete(req, results); } else{ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unknown command " + command); } rsp.add("results", results); }
Example 20
Source File: NodeNormalizerTest.java From semantic-knowledge-graph with Apache License 2.0 | 4 votes |
@Test public void populateNorms_Id() { NodeNormalizer target = new NodeNormalizer(); FacetFieldAdapter adapter = new FacetFieldAdapter("testField"); AggregationWaitable runner = new AggregationWaitable(context, adapter, "testField", 0, 1); runner.buckets = new LinkedList<>(); runner.adapter = adapter; SimpleOrderedMap<Object> bucket1 = new SimpleOrderedMap<>(); bucket1.add("val", "testValue1"); bucket1.add("id", "1"); SimpleOrderedMap<Object> bucket2 = new SimpleOrderedMap<>(); bucket2.add("val", "testValue2"); bucket2.add("id", "2"); SimpleOrderedMap<Object> bucket3 = new SimpleOrderedMap<>(); bucket3.add("val", "value3"); bucket3.add("id", "3"); runner.buckets.add(bucket1); runner.buckets.add(bucket2); runner.buckets.add(bucket3); String requestValue1 = "1"; String requestValue2 = "2"; LinkedList<String> normalizedStrings = new LinkedList<>(); LinkedList<SimpleOrderedMap<String>> normalizedMaps = new LinkedList<>(); String [] expectedStrings = new String [] {"testValue1", "testValue2"}; LinkedList<SimpleOrderedMap<String>> expectedMaps = new LinkedList<>(); SimpleOrderedMap<String> map1 = new SimpleOrderedMap<>(); map1.add("name", "testValue1"); map1.add("id", "1"); SimpleOrderedMap<String> map2 = new SimpleOrderedMap<>(); map2.add("name", "testValue2"); map2.add("id", "2"); expectedMaps.add(map1); expectedMaps.add(map2); Deencapsulation.invoke(target, "populateNorms", runner, requestValue1, normalizedStrings, normalizedMaps); Deencapsulation.invoke(target, "populateNorms", runner, requestValue2, normalizedStrings, normalizedMaps); Assert.assertEquals(2, normalizedStrings.size()); Assert.assertEquals(2, normalizedMaps.size()); for(int i = 0; i < expectedStrings.length ; ++i) { Assert.assertEquals(expectedMaps.get(i),normalizedMaps.get(i)); Assert.assertEquals(expectedStrings[i],normalizedStrings.get(i)); } }