Search in sources :

Example 61 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithFilter.

@Test
public void testCollateWithFilter() throws Exception {
    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_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10");
    params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)");
    params.add(CommonParams.FQ, "NOT(id:1)");
    //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
    //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
    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 collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() > 0);
    for (String collation : collations) {
        assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)"));
    }
}
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) SearchComponent(org.apache.solr.handler.component.SearchComponent) 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 62 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithGrouping.

@Test
public void testCollateWithGrouping() throws Exception {
    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_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    params.add(GroupParams.GROUP, "true");
    params.add(GroupParams.GROUP_FIELD, "id");
    //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
    //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
    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 collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() == 1);
}
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) SearchComponent(org.apache.solr.handler.component.SearchComponent) 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 63 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SpellCheckCollatorTest method testZeroTries.

@Test
public void testZeroTries() throws Exception {
    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(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
    params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    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 collationList = (NamedList) spellCheck.get("collations");
    List<?> collations = (List<?>) collationList.getAll("collation");
    assertTrue(collations.size() == 2);
}
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) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) 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 64 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class CloudSolrClient method condenseResponse.

public RouteResponse condenseResponse(NamedList response, int timeMillis) {
    RouteResponse condensed = new RouteResponse();
    int status = 0;
    Integer rf = null;
    Integer minRf = null;
    // TolerantUpdateProcessor
    List<SimpleOrderedMap<String>> toleratedErrors = null;
    int maxToleratedErrors = Integer.MAX_VALUE;
    // For "adds", "deletes", "deleteByQuery" etc.
    Map<String, NamedList> versions = new HashMap<>();
    for (int i = 0; i < response.size(); i++) {
        NamedList shardResponse = (NamedList) response.getVal(i);
        NamedList header = (NamedList) shardResponse.get("responseHeader");
        Integer shardStatus = (Integer) header.get("status");
        int s = shardStatus.intValue();
        if (s > 0) {
            status = s;
        }
        Object rfObj = header.get(UpdateRequest.REPFACT);
        if (rfObj != null && rfObj instanceof Integer) {
            Integer routeRf = (Integer) rfObj;
            if (rf == null || routeRf < rf)
                rf = routeRf;
        }
        minRf = (Integer) header.get(UpdateRequest.MIN_REPFACT);
        List<SimpleOrderedMap<String>> shardTolerantErrors = (List<SimpleOrderedMap<String>>) header.get("errors");
        if (null != shardTolerantErrors) {
            Integer shardMaxToleratedErrors = (Integer) header.get("maxErrors");
            assert null != shardMaxToleratedErrors : "TolerantUpdateProcessor reported errors but not maxErrors";
            // if we get into some weird state where the nodes disagree about the effective maxErrors,
            // assume the min value seen to decide if we should fail.
            maxToleratedErrors = Math.min(maxToleratedErrors, ToleratedUpdateError.getEffectiveMaxErrors(shardMaxToleratedErrors.intValue()));
            if (null == toleratedErrors) {
                toleratedErrors = new ArrayList<SimpleOrderedMap<String>>(shardTolerantErrors.size());
            }
            for (SimpleOrderedMap<String> err : shardTolerantErrors) {
                toleratedErrors.add(err);
            }
        }
        for (String updateType : Arrays.asList("adds", "deletes", "deleteByQuery")) {
            Object obj = shardResponse.get(updateType);
            if (obj instanceof NamedList) {
                NamedList versionsList = versions.containsKey(updateType) ? versions.get(updateType) : new NamedList();
                versionsList.addAll((NamedList) obj);
                versions.put(updateType, versionsList);
            }
        }
    }
    NamedList cheader = new NamedList();
    cheader.add("status", status);
    cheader.add("QTime", timeMillis);
    if (rf != null)
        cheader.add(UpdateRequest.REPFACT, rf);
    if (minRf != null)
        cheader.add(UpdateRequest.MIN_REPFACT, minRf);
    if (null != toleratedErrors) {
        cheader.add("maxErrors", ToleratedUpdateError.getUserFriendlyMaxErrors(maxToleratedErrors));
        cheader.add("errors", toleratedErrors);
        if (maxToleratedErrors < toleratedErrors.size()) {
            // cumulative errors are too high, we need to throw a client exception w/correct metadata
            // NOTE: it shouldn't be possible for 1 == toleratedErrors.size(), because if that were the case
            // then at least one shard should have thrown a real error before this, so we don't worry
            // about having a more "singular" exception msg for that situation
            StringBuilder msgBuf = new StringBuilder().append(toleratedErrors.size()).append(" Async failures during distributed update: ");
            NamedList metadata = new NamedList<String>();
            for (SimpleOrderedMap<String> err : toleratedErrors) {
                ToleratedUpdateError te = ToleratedUpdateError.parseMap(err);
                metadata.add(te.getMetadataKey(), te.getMetadataValue());
                msgBuf.append("\n").append(te.getMessage());
            }
            SolrException toThrow = new SolrException(ErrorCode.BAD_REQUEST, msgBuf.toString());
            toThrow.setMetadata(metadata);
            throw toThrow;
        }
    }
    for (String updateType : versions.keySet()) {
        condensed.add(updateType, versions.get(updateType));
    }
    condensed.add("responseHeader", cheader);
    return condensed;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) ToleratedUpdateError(org.apache.solr.common.ToleratedUpdateError) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) SolrException(org.apache.solr.common.SolrException)

Example 65 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class HttpClusterStateProvider method fetchLiveNodes.

private static Set<String> fetchLiveNodes(SolrClient client) throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", "CLUSTERSTATUS");
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    NamedList cluster = (SimpleOrderedMap) client.request(request).get("cluster");
    Set<String> liveNodes = new HashSet((List<String>) (cluster.get("live_nodes")));
    return liveNodes;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HashSet(java.util.HashSet)

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