Search in sources :

Example 61 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class DateRangeField method parseSpatialArgs.

@Override
protected SpatialArgs parseSpatialArgs(QParser parser, String externalVal) {
    //We avoid SpatialArgsParser entirely because it isn't very Solr-friendly
    final Shape shape = parseShape(externalVal);
    final SolrParams localParams = parser.getLocalParams();
    SpatialOperation op = SpatialOperation.Intersects;
    if (localParams != null) {
        String opStr = localParams.get(OP_PARAM);
        if (opStr != null)
            op = SpatialOperation.get(opStr);
    }
    return new SpatialArgs(op, shape);
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) NRShape(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.NRShape) Shape(org.locationtech.spatial4j.shape.Shape) UnitNRShape(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape) SolrParams(org.apache.solr.common.params.SolrParams) SpatialOperation(org.apache.lucene.spatial.query.SpatialOperation)

Example 62 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class HttpSolrCall method getAuthCtx.

private AuthorizationContext getAuthCtx() {
    String resource = getPath();
    SolrParams params = getQueryParams();
    final ArrayList<CollectionRequest> collectionRequests = new ArrayList<>();
    if (getCollectionsList() != null) {
        for (String collection : getCollectionsList()) {
            collectionRequests.add(new CollectionRequest(collection));
        }
    }
    // Extract collection name from the params in case of a Collection Admin request
    if (getPath().equals("/admin/collections")) {
        if (CREATE.isEqual(params.get("action")) || RELOAD.isEqual(params.get("action")) || DELETE.isEqual(params.get("action")))
            collectionRequests.add(new CollectionRequest(params.get("name")));
        else if (params.get(COLLECTION_PROP) != null)
            collectionRequests.add(new CollectionRequest(params.get(COLLECTION_PROP)));
    }
    // Handle the case when it's a /select request and collections are specified as a param
    if (resource.equals("/select") && params.get("collection") != null) {
        collectionRequests.clear();
        for (String collection : params.get("collection").split(",")) {
            collectionRequests.add(new CollectionRequest(collection));
        }
    }
    // Populate the request type if the request is select or update
    if (requestType == RequestType.UNKNOWN) {
        if (resource.startsWith("/select") || resource.startsWith("/get"))
            requestType = RequestType.READ;
        if (resource.startsWith("/update"))
            requestType = RequestType.WRITE;
    }
    // the purpose of processing this request.
    if (getCore() != null && (getCollectionsList() == null || getCollectionsList().size() == 0)) {
        collectionRequests.add(new CollectionRequest(getCore().getCoreDescriptor().getCollectionName()));
    }
    if (getQueryParams().get(COLLECTION_PROP) != null)
        collectionRequests.add(new CollectionRequest(getQueryParams().get(COLLECTION_PROP)));
    return new AuthorizationContext() {

        @Override
        public SolrParams getParams() {
            return null == solrReq ? null : solrReq.getParams();
        }

        @Override
        public Principal getUserPrincipal() {
            return getReq().getUserPrincipal();
        }

        @Override
        public String getHttpHeader(String s) {
            return getReq().getHeader(s);
        }

        @Override
        public Enumeration getHeaderNames() {
            return getReq().getHeaderNames();
        }

        @Override
        public List<CollectionRequest> getCollectionRequests() {
            return collectionRequests;
        }

        @Override
        public RequestType getRequestType() {
            return requestType;
        }

        public String getResource() {
            return path;
        }

        @Override
        public String getHttpMethod() {
            return getReq().getMethod();
        }

        @Override
        public Object getHandler() {
            return _getHandler();
        }

        @Override
        public String toString() {
            StringBuilder response = new StringBuilder("userPrincipal: [").append(getUserPrincipal()).append("]").append(" type: [").append(requestType.toString()).append("], collections: [");
            for (CollectionRequest collectionRequest : collectionRequests) {
                response.append(collectionRequest.collectionName).append(", ");
            }
            if (collectionRequests.size() > 0)
                response.delete(response.length() - 1, response.length());
            response.append("], Path: [").append(resource).append("]");
            response.append(" path : ").append(path).append(" params :").append(getParams());
            return response.toString();
        }

        @Override
        public String getRemoteAddr() {
            return getReq().getRemoteAddr();
        }

        @Override
        public String getRemoteHost() {
            return getReq().getRemoteHost();
        }
    };
}
Also used : CollectionRequest(org.apache.solr.security.AuthorizationContext.CollectionRequest) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) AuthorizationContext(org.apache.solr.security.AuthorizationContext)

Example 63 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class HttpSolrCall method sendError.

protected void sendError(Throwable ex) throws IOException {
    Exception exp = null;
    SolrCore localCore = null;
    try {
        SolrQueryResponse solrResp = new SolrQueryResponse();
        if (ex instanceof Exception) {
            solrResp.setException((Exception) ex);
        } else {
            solrResp.setException(new RuntimeException(ex));
        }
        localCore = core;
        if (solrReq == null) {
            final SolrParams solrParams;
            if (req != null) {
                // use GET parameters if available:
                solrParams = SolrRequestParsers.parseQueryString(req.getQueryString());
            } else {
                // we have no params at all, use empty ones:
                solrParams = new MapSolrParams(Collections.<String, String>emptyMap());
            }
            solrReq = new SolrQueryRequestBase(core, solrParams) {
            };
        }
        QueryResponseWriter writer = core.getQueryResponseWriter(solrReq);
        writeResponse(solrResp, writer, Method.GET);
    } catch (Exception e) {
        // This error really does not matter
        exp = e;
    } finally {
        try {
            if (exp != null) {
                SimpleOrderedMap info = new SimpleOrderedMap();
                int code = ResponseUtils.getErrorInfo(ex, info, log);
                sendError(code, info.toString());
            }
        } finally {
            if (core == null && localCore != null) {
                localCore.close();
            }
        }
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) EOFException(java.io.EOFException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper.KeeperException)

Example 64 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class DirectSolrSpellChecker method init.

@Override
public String init(NamedList config, SolrCore core) {
    SolrParams params = SolrParams.toSolrParams(config);
    LOG.info("init: " + config);
    String name = super.init(config, core);
    Comparator<SuggestWord> comp = SuggestWordQueue.DEFAULT_COMPARATOR;
    String compClass = (String) config.get(COMPARATOR_CLASS);
    if (compClass != null) {
        if (compClass.equalsIgnoreCase(SCORE_COMP))
            comp = SuggestWordQueue.DEFAULT_COMPARATOR;
        else if (compClass.equalsIgnoreCase(FREQ_COMP))
            comp = new SuggestWordFrequencyComparator();
        else
            //must be a FQCN
            comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class);
    }
    StringDistance sd = DirectSpellChecker.INTERNAL_LEVENSHTEIN;
    String distClass = (String) config.get(STRING_DISTANCE);
    if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
        sd = core.getResourceLoader().newInstance(distClass, StringDistance.class);
    float minAccuracy = DEFAULT_ACCURACY;
    Float accuracy = params.getFloat(ACCURACY);
    if (accuracy != null)
        minAccuracy = accuracy;
    int maxEdits = DEFAULT_MAXEDITS;
    Integer edits = params.getInt(MAXEDITS);
    if (edits != null)
        maxEdits = edits;
    int minPrefix = DEFAULT_MINPREFIX;
    Integer prefix = params.getInt(MINPREFIX);
    if (prefix != null)
        minPrefix = prefix;
    int maxInspections = DEFAULT_MAXINSPECTIONS;
    Integer inspections = params.getInt(MAXINSPECTIONS);
    if (inspections != null)
        maxInspections = inspections;
    float minThreshold = DEFAULT_THRESHOLD_TOKEN_FREQUENCY;
    Float threshold = params.getFloat(THRESHOLD_TOKEN_FREQUENCY);
    if (threshold != null)
        minThreshold = threshold;
    int minQueryLength = DEFAULT_MINQUERYLENGTH;
    Integer queryLength = params.getInt(MINQUERYLENGTH);
    if (queryLength != null)
        minQueryLength = queryLength;
    float maxQueryFrequency = DEFAULT_MAXQUERYFREQUENCY;
    Float queryFreq = params.getFloat(MAXQUERYFREQUENCY);
    if (queryFreq != null)
        maxQueryFrequency = queryFreq;
    checker.setComparator(comp);
    checker.setDistance(sd);
    checker.setMaxEdits(maxEdits);
    checker.setMinPrefix(minPrefix);
    checker.setAccuracy(minAccuracy);
    checker.setThresholdFrequency(minThreshold);
    checker.setMaxInspections(maxInspections);
    checker.setMinQueryLength(minQueryLength);
    checker.setMaxQueryFrequency(maxQueryFrequency);
    checker.setLowerCaseTerms(false);
    return name;
}
Also used : SuggestWordFrequencyComparator(org.apache.lucene.search.spell.SuggestWordFrequencyComparator) StringDistance(org.apache.lucene.search.spell.StringDistance) SuggestWord(org.apache.lucene.search.spell.SuggestWord) SolrParams(org.apache.solr.common.params.SolrParams)

Example 65 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class DirectSolrConnection method request.

/**
   * For example:
   * 
   * String json = solr.request( "/select?qt=dismax&amp;wt=json&amp;q=...", null );
   * String xml = solr.request( "/update", "&lt;add&gt;&lt;doc&gt;&lt;field ..." );
   */
public String request(String pathAndParams, String body) throws Exception {
    String path = null;
    SolrParams params = null;
    int idx = pathAndParams.indexOf('?');
    if (idx > 0) {
        path = pathAndParams.substring(0, idx);
        params = SolrRequestParsers.parseQueryString(pathAndParams.substring(idx + 1));
    } else {
        path = pathAndParams;
        params = new MapSolrParams(new HashMap<String, String>());
    }
    return request(path, params, body);
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams)

Aggregations

SolrParams (org.apache.solr.common.params.SolrParams)310 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)179 SolrException (org.apache.solr.common.SolrException)78 Test (org.junit.Test)45 Tuple (org.apache.solr.client.solrj.io.Tuple)43 SolrDocument (org.apache.solr.common.SolrDocument)42 ArrayList (java.util.ArrayList)41 NamedList (org.apache.solr.common.util.NamedList)40 MapSolrParams (org.apache.solr.common.params.MapSolrParams)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 IOException (java.io.IOException)35 SolrDocumentList (org.apache.solr.common.SolrDocumentList)34 HashMap (java.util.HashMap)33 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)27 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)26 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)24 Map (java.util.Map)22 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)22 SolrCore (org.apache.solr.core.SolrCore)20