use of org.apache.solr.common.util.SimpleOrderedMap in project jackrabbit-oak by apache.
the class SolrQueryIndex method putSuggestions.
private void putSuggestions(Set<Map.Entry<String, Object>> suggestEntries, final Deque<SolrResultRow> queue, Filter filter, OakSolrConfiguration configuration, SolrServer solrServer) throws SolrServerException {
Collection<SimpleOrderedMap<Object>> retrievedSuggestions = new HashSet<SimpleOrderedMap<Object>>();
for (Map.Entry<String, Object> suggester : suggestEntries) {
SimpleOrderedMap<Object> suggestionResponses = ((SimpleOrderedMap) suggester.getValue());
for (Map.Entry<String, Object> suggestionResponse : suggestionResponses) {
SimpleOrderedMap<Object> suggestionResults = ((SimpleOrderedMap) suggestionResponse.getValue());
for (Map.Entry<String, Object> suggestionResult : suggestionResults) {
if ("suggestions".equals(suggestionResult.getKey())) {
ArrayList<SimpleOrderedMap<Object>> suggestions = ((ArrayList<SimpleOrderedMap<Object>>) suggestionResult.getValue());
if (!suggestions.isEmpty()) {
for (SimpleOrderedMap<Object> suggestion : suggestions) {
retrievedSuggestions.add(suggestion);
}
}
}
}
}
}
// ACL filter suggestions
for (SimpleOrderedMap<Object> suggestion : retrievedSuggestions) {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setParam("q", String.valueOf(suggestion.get("term")));
solrQuery.setParam("df", configuration.getCatchAllField());
solrQuery.setParam("q.op", "AND");
solrQuery.setParam("rows", "100");
QueryResponse suggestQueryResponse = solrServer.query(solrQuery);
SolrDocumentList results = suggestQueryResponse.getResults();
if (results != null && results.getNumFound() > 0) {
for (SolrDocument doc : results) {
if (filter.isAccessible(String.valueOf(doc.getFieldValue(configuration.getPathField())))) {
queue.add(new SolrResultRow(suggestion.get("term").toString(), Double.parseDouble(suggestion.get("weight").toString())));
break;
}
}
}
}
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class TestJsonFacetRefinement method fromJSON.
/** Use SimpleOrderedMap rather than Map to match responses from shards */
public static Object fromJSON(String json) throws IOException {
JSONParser parser = new JSONParser(json);
ObjectBuilder ob = new ObjectBuilder(parser) {
@Override
public Object newObject() throws IOException {
return new SimpleOrderedMap();
}
@Override
public void addKeyVal(Object map, Object key, Object val) throws IOException {
((SimpleOrderedMap) map).add(key.toString(), val);
}
};
return ob.getObject();
}
use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.
the class SpellCheckComponentTest method testThresholdTokenFrequency.
@Test
public void testThresholdTokenFrequency() throws Exception {
//"document" is in 2 documents but "another" is only in 1.
//So with a threshold of 29%, "another" is absent from the dictionary
//while "document" is present.
assertJQ(req("qt", rh, SpellCheckComponent.COMPONENT_NAME, "true", "q", "documenq", SpellingParams.SPELLCHECK_DICT, "threshold", SpellingParams.SPELLCHECK_COUNT, "5", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true"), "/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]");
assertJQ(req("qt", rh, SpellCheckComponent.COMPONENT_NAME, "true", "q", "documenq", SpellingParams.SPELLCHECK_DICT, "threshold_direct", SpellingParams.SPELLCHECK_COUNT, "5", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true"), "/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]");
//TODO: how do we make this into a 1-liner using "assertQ()" ???
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellingParams.SPELLCHECK_COUNT, "10");
params.add(SpellingParams.SPELLCHECK_DICT, "threshold");
params.add(SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true");
params.add(CommonParams.Q, "anotheq");
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList suggestions = (NamedList) spellCheck.get("suggestions");
assertTrue(suggestions.get("suggestion") == null);
assertTrue((Boolean) spellCheck.get("correctlySpelled") == false);
params.remove(SpellingParams.SPELLCHECK_DICT);
params.add(SpellingParams.SPELLCHECK_DICT, "threshold_direct");
rsp = new SolrQueryResponse();
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
values = rsp.getValues();
spellCheck = (NamedList) values.get("spellcheck");
suggestions = (NamedList) spellCheck.get("suggestions");
assertTrue(suggestions.get("suggestion") == null);
assertTrue((Boolean) spellCheck.get("correctlySpelled") == false);
}
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);
}
}
Aggregations