Search in sources :

Example 66 with SimpleOrderedMap

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;
                }
            }
        }
    }
}
Also used : SolrDocumentList(org.apache.solr.common.SolrDocumentList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) HashSet(java.util.HashSet)

Example 67 with SimpleOrderedMap

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();
}
Also used : JSONParser(org.noggit.JSONParser) ObjectBuilder(org.noggit.ObjectBuilder) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 68 with SimpleOrderedMap

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);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 69 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 70 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)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)132 NamedList (org.apache.solr.common.util.NamedList)70 ArrayList (java.util.ArrayList)37 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)28 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 List (java.util.List)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)19 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