Example usage for org.apache.solr.common.params CursorMarkParams CURSOR_MARK_PARAM

List of usage examples for org.apache.solr.common.params CursorMarkParams CURSOR_MARK_PARAM

Introduction

In this page you can find the example usage for org.apache.solr.common.params CursorMarkParams CURSOR_MARK_PARAM.

Prototype

String CURSOR_MARK_PARAM

To view the source code for org.apache.solr.common.params CursorMarkParams CURSOR_MARK_PARAM.

Click Source Link

Document

Param clients should specify indicating that they want a cursor based search.

Usage

From source file:bamboo.trove.rule.RuleChangeUpdateManager.java

License:Apache License

private void processQuery(SolrQuery query, WorkLog workLog) throws SolrServerException, IOException {
    log.debug("Query for rule : {}", query.toString());
    Timer.Context context = getTimer(getName() + ".processQuery").time();
    // need to commit here so that we can ignore documents just processed
    client.commit();/*ww w . ja  va  2 s . co m*/

    boolean more = true;
    String cursor = CursorMarkParams.CURSOR_MARK_START;
    while (more) {
        query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor);
        Timer.Context contextQuery = getTimer(getName() + ".query").time();

        QueryResponse response = client.query(query);
        workLog.ranSearch();
        SolrDocumentList results = response.getResults();
        log.debug("Found {} (of {} docs) in QT = {} ms", results.size(), results.getNumFound(),
                response.getQTime());
        String nextCursor = response.getNextCursorMark();
        if (nextCursor == null || cursor.equals(nextCursor)) {
            more = false;
        }
        distributeResponse(results, workLog);
        cursor = nextCursor;
        contextQuery.stop();
    }

    // We do this at a higher level too, so this would seem redundant. There is a trade-off. Allowing parallelism
    // between rules means rules can sometimes be re-processed redundantly. The higher level waitUntilCaughtUp() will
    // ensure we never process rules at the same time rules are being changed.
    // By doing a wait here as well however, we can collect accurate statistics about how much actual write activity we
    // are really generating by passing the workLog into the work pool.
    // When we have a better awareness of the typical work patterns it might be worth disabling this method call and
    // then stop collecting the metrics to improve throughput.
    waitUntilCaughtUp();
    context.stop();
}

From source file:com.frank.search.solr.core.query.result.DelegatingCursor.java

License:Apache License

private void load(String cursorMark) {

    SolrQuery query = referenceQuery.getCopy();
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, this.getCursorMark());

    PartialResult<T> result = doLoad(query);
    process(result);//from  w  w w  .j av  a 2 s  .c  om
}

From source file:com.hurence.logisland.service.solr.api.SolrClientService.java

License:Apache License

@Override
public void copyCollection(String reindexScrollTimeout, String src, String dst)
        throws DatastoreClientServiceException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setRows(1000);/*w  ww .  j a v a2  s.  c om*/
    solrQuery.setQuery("*:*");
    solrQuery.addSort("id", SolrQuery.ORDER.asc); // Pay attention to this line
    String cursorMark = CursorMarkParams.CURSOR_MARK_START;
    boolean done = false;
    QueryResponse response;
    try {
        do {
            solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
            response = getClient().query(src, solrQuery);
            List<SolrInputDocument> documents = new ArrayList<>();
            for (SolrDocument document : response.getResults()) {
                SolrInputDocument inputDocument = getConverter().toSolrInputDocument(document);
                inputDocument.removeField("_version_");
                documents.add(inputDocument);
            }

            getClient().add(dst, documents);

        } while (cursorMark.equals(response.getNextCursorMark()));

        getClient().commit(dst);
    } catch (Exception e) {
        throw new DatastoreClientServiceException(e);
    }
}

From source file:it.damore.solr.importexport.App.java

License:Open Source License

/**
 * @param client//from  w  w w.j  av a 2s  .c om
 * @param outputFile
 * @throws SolrServerException
 * @throws IOException
 */
private static void readAllDocuments(HttpSolrClient client, File outputFile)
        throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    if (config.getFilterQuery() != null) {
        solrQuery.addFilterQuery(config.getFilterQuery());
    }
    solrQuery.setRows(0);

    solrQuery.addSort(config.getUniqueKey(), ORDER.asc); // Pay attention to this line

    String cursorMark = CursorMarkParams.CURSOR_MARK_START;

    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    // objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    DateFormat df = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:sss'Z'");
    objectMapper.setDateFormat(df);
    objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);

    QueryResponse r = client.query(solrQuery);

    long nDocuments = r.getResults().getNumFound();
    logger.info("Found " + nDocuments + " documents");

    if (!config.getDryRun()) {
        logger.info("Creating " + config.getFileName());

        Set<SkipField> skipFieldsEquals = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.EQUAL).collect(Collectors.toSet());
        Set<SkipField> skipFieldsStartWith = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.STARTS_WITH).collect(Collectors.toSet());
        Set<SkipField> skipFieldsEndWith = config.getSkipFieldsSet().stream()
                .filter(s -> s.getMatch() == MatchType.ENDS_WITH).collect(Collectors.toSet());

        try (PrintWriter pw = new PrintWriter(outputFile)) {
            solrQuery.setRows(200);
            boolean done = false;
            while (!done) {
                solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
                QueryResponse rsp = client.query(solrQuery);
                String nextCursorMark = rsp.getNextCursorMark();

                for (SolrDocument d : rsp.getResults()) {
                    skipFieldsEquals.forEach(f -> d.removeFields(f.getText()));
                    if (skipFieldsStartWith.size() > 0 || skipFieldsEndWith.size() > 0) {
                        Map<String, Object> collect = d.entrySet().stream()
                                .filter(e -> !skipFieldsStartWith.stream()
                                        .filter(f -> e.getKey().startsWith(f.getText())).findFirst()
                                        .isPresent())
                                .filter(e -> !skipFieldsEndWith.stream()
                                        .filter(f -> e.getKey().endsWith(f.getText())).findFirst().isPresent())
                                .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
                        pw.write(objectMapper.writeValueAsString(collect));
                    } else {
                        pw.write(objectMapper.writeValueAsString(d));
                    }
                    pw.write("\n");
                }
                if (cursorMark.equals(nextCursorMark)) {
                    done = true;
                }

                cursorMark = nextCursorMark;
            }

        }
    }

}

From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java

License:Apache License

public QueryResponse getSolr4Docs(String solrServer, String solrCoreName, String uniqueKey, List<String> fields,
        Long solrDocFectCount, String cursorMark, StringBuilder filters, List<SolrAggrParam> solrAggrParams,
        List<SolrSortParam> solrSortParams, List<String> aggrFieldNames, boolean isGroup,
        boolean useFacetPivotFromGroupCount) {

    String solrUrl = solrServer;//w  ww. ja v  a 2  s . c o  m
    if (solrCoreName != null) {
        solrUrl = solrServer + solrCoreName;
    }
    SolrClient solrClient = new HttpSolrClient(solrUrl);
    String fieldStr = null;
    String[] fieldListArr = null;
    List<String> statsFieldList = Lists.newArrayList();

    SolrQuery solrQuery = new SolrQuery().setTermsRegexFlag("case_insensitive").setQuery(uniqueKey + ":*")
            .setRows(0);

    if (filters.length() > 0) {
        solrQuery.setParam("fq", filters.toString());
        SolrClientAPIExec.logger.debug("Filter query [ " + filters.toString() + " ]");
    }

    if (!fields.isEmpty()) {
        fieldStr = Joiner.on(",").join(fields);
        solrQuery.setParam("fl", fieldStr);
        solrQuery.setRows(solrDocFectCount.intValue());
        SolrClientAPIExec.logger.debug("Response field list [" + fieldStr + "]");
    }
    // facet.pivot={!stats=s1}category,manufacturer
    // stats.field={!key=avg_price tag=s1 mean=true}price
    // stats.field={!tag=s1 min=true max=true}user_rating

    if (solrAggrParams != null && !solrAggrParams.isEmpty() && !useFacetPivotFromGroupCount) {
        solrQuery.setGetFieldStatistics(true);
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String statsField = solrAggrParam.getFieldName();
            if (!fields.contains(statsField)) {
                statsField = uniqueKey;
            }
            if (!statsFieldList.contains(statsField)) {
                statsFieldList.add(statsField);
            }
            fields.remove(statsField);
        }
        if (!fields.isEmpty()) {
            fieldListArr = fields.toArray(new String[fields.size()]);
        }

        for (String statsField : statsFieldList) {
            solrQuery.setGetFieldStatistics(statsField);
            SolrClientAPIExec.logger.debug("Adding stats field parameter.. [ " + statsField + " ]");
            if (isGroup) {
                List<String> groupFields = Lists.newArrayList();
                for (String aggrField : aggrFieldNames) {
                    if (fields.contains(aggrField)) {
                        groupFields.add(aggrField);
                    }
                }
                SolrClientAPIExec.logger.debug("Adding stats facet parameters.. [ " + groupFields + " ]");
                solrQuery.addStatsFieldFacets(statsField, groupFields.toArray(new String[groupFields.size()]));
            }

        }
        solrQuery.setRows(0);
    } else if (isGroup) {
        fieldListArr = fields.toArray(new String[fields.size()]);
        solrQuery.setFacet(true);
        if (fields.size() == 1) {
            solrQuery.addFacetField(fieldListArr);
            solrQuery.setFacetLimit(-1);
        } else {
            solrQuery.addFacetPivotField(Joiner.on(",").join(fields));
        }
        solrQuery.setRows(0);
        solrQuery.setFacetMinCount(1);

        // solrQuery.set(GroupParams.GROUP, true);
        // solrQuery.set(GroupParams.GROUP_FIELD, fieldListArr);
        // solrQuery.set(GroupParams.GROUP_MAIN, true);
        // solrQuery.set(GroupParams.GROUP_FORMAT, "simple");
        // solrQuery.set("group.ngroups", "true");
    }
    if (!solrSortParams.isEmpty()) {
        for (SolrSortParam solrSortParam : solrSortParams) {
            String solrSortField = solrSortParam.getSortFieldName();
            ORDER solrSortDir = solrSortParam.getSortDir();
            solrQuery.addSort(solrSortField, solrSortDir);

        }
    } else {
        solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
        solrQuery.setSort(SolrQuery.SortClause.desc(uniqueKey));
    }
    QueryResponse rsp = null;
    try {
        SolrClientAPIExec.logger
                .info("Submitting Query :" + solrServer + "/select" + solrQuery.toQueryString());

        rsp = solrClient.query(solrQuery);

        SolrClientAPIExec.logger.info("Response recieved from [ " + solrServer + " ] core [ " + solrCoreName
                + " ] in " + rsp.getQTime() + " MS.");

    } catch (SolrServerException | IOException e) {
        SolrClientAPIExec.logger
                .debug("Error occured while fetching results from solr server " + e.getMessage());
    } finally {
        try {
            solrClient.close();
        } catch (IOException e) {
            SolrClientAPIExec.logger
                    .debug("Error occured while closing connection of solr server " + e.getMessage());
        }
    }

    return rsp;
}

From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java

License:Apache License

public QueryResponse getSolrDocs(String solrServer, String solrCoreName, String uniqueKey, List<String> fields,
        Long solrDocFectCount, String cursorMark, StringBuilder filters, List<SolrAggrParam> solrAggrParams,
        List<SolrSortParam> solrSortParams, List<String> aggrFieldNames, boolean isGroup,
        boolean isCountOnlyQuery) {

    String solrUrl = solrServer;// w w  w . j  a  va 2 s  . c  om
    if (solrCoreName != null) {
        solrUrl = solrServer + solrCoreName;
    }
    SolrClient solrClient = new HttpSolrClient(solrUrl);

    String fieldStr = null;
    String[] fieldListArr = null;
    List<String> statsFieldList = Lists.newArrayList();

    SolrQuery solrQuery = new SolrQuery().setQuery("{!cache=false}" + uniqueKey + ":*").setRows(0);

    if (filters.length() > 0) {
        solrQuery.setParam("fq", filters.toString());
        SolrClientAPIExec.logger.debug("Filter query [ " + filters.toString() + " ]");
    }

    if (!fields.isEmpty()) {
        fieldStr = Joiner.on(",").join(fields);
        solrQuery.setParam("fl", fieldStr);
        solrQuery.setRows(solrDocFectCount.intValue());
        SolrClientAPIExec.logger.debug("Response field list [" + fieldStr + "]");
    }
    if (solrAggrParams != null && !solrAggrParams.isEmpty() && !isCountOnlyQuery) {
        solrQuery.setGetFieldStatistics(true);
        String referenceToStatsTag = "{!stats=t1}";
        String statsTag = "{!tag=t1}";
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String statsField = solrAggrParam.getFieldName();
            if (!fields.contains(statsField)) {
                statsField = uniqueKey;
            }
            if (!statsFieldList.contains(statsField)) {
                statsFieldList.add(statsField);
            }
            fields.remove(statsField);
        }
        if (!fields.isEmpty()) {
            fieldListArr = fields.toArray(new String[fields.size()]);
        }
        SolrClientAPIExec.logger.debug("Adding stats field parameter.." + statsFieldList + "");

        if (isGroup) {
            List<String> groupFields = Lists.newArrayList();
            solrQuery.addGetFieldStatistics(statsTag + Joiner.on(",").join(statsFieldList));
            for (String aggrField : fields) {
                if (fields.contains(aggrField)) {
                    groupFields.add(aggrField);
                }
            }
            if (groupFields.size() == 1) {
                SolrClientAPIExec.logger.debug("Adding stats facet parameters.." + groupFields + "");
                for (String statsField : statsFieldList) {
                    solrQuery.addStatsFieldFacets(statsField,
                            groupFields.toArray(new String[groupFields.size()]));
                }
            } else {
                SolrClientAPIExec.logger.debug("Adding facet pivot parameters.." + groupFields + "");
                solrQuery.addFacetPivotField(referenceToStatsTag + Joiner.on(",").join(groupFields));
                solrQuery.setFacetLimit(-1);
            }
        } else {
            for (String statsField : statsFieldList) {
                solrQuery.setGetFieldStatistics(statsField);
            }
        }
        solrQuery.setRows(0);
    } else if (isGroup) {
        fieldListArr = fields.toArray(new String[fields.size()]);
        solrQuery.setFacet(true);
        if (fields.size() == 1) {
            solrQuery.addFacetField(fieldListArr);
            solrQuery.setFacetLimit(-1);
        } else {
            solrQuery.addFacetPivotField(Joiner.on(",").join(fields));
        }
        solrQuery.setRows(0);
        solrQuery.setFacetMinCount(1);
        solrQuery.setFacetLimit(-1);
    } else {
        solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
        solrQuery.addSort(SolrQuery.SortClause.desc(uniqueKey));

    }
    if (!solrSortParams.isEmpty()) {
        for (SolrSortParam solrSortParam : solrSortParams) {
            String solrSortField = solrSortParam.getSortFieldName();
            ORDER solrSortDir = solrSortParam.getSortDir();
            solrQuery.addSort(solrSortField, solrSortDir);

        }
    }

    QueryResponse rsp = null;
    try {
        SolrClientAPIExec.logger.info("Submitting Query :" + solrUrl + "/select" + solrQuery.toQueryString());

        rsp = solrClient.query(solrQuery);

        SolrClientAPIExec.logger.info("Response recieved from [ " + solrServer + " ] core [ " + solrCoreName
                + " ] in " + rsp.getQTime() + " MS.");

    } catch (SolrServerException | IOException e) {
        SolrClientAPIExec.logger
                .debug("Error occured while fetching results from solr server " + e.getMessage());
    } finally {
        try {
            solrClient.close();
        } catch (IOException e) {
            SolrClientAPIExec.logger
                    .debug("Error occured while closing connection of solr server " + e.getMessage());
        }
    }

    return rsp;
}

From source file:org.apache.metron.solr.dao.SolrMetaAlertSearchDao.java

License:Apache License

@Override
public SearchResponse getAllMetaAlertsForAlert(String guid) throws InvalidSearchException {
    if (guid == null || guid.trim().isEmpty()) {
        throw new InvalidSearchException("Guid cannot be empty");
    }//from  w ww. j  ava2s  .  c  om

    // Searches for all alerts containing the meta alert guid in it's "metalerts" array
    // The query has to match the parentFilter to avoid errors.  Guid must also be explicitly
    // included.
    String activeClause = MetaAlertConstants.STATUS_FIELD + ":" + MetaAlertStatus.ACTIVE.getStatusString();
    String guidClause = Constants.GUID + ":" + guid;
    String fullClause = "{!parent which=" + activeClause + "}" + guidClause;
    String metaalertTypeClause = config.getSourceTypeField() + ":" + MetaAlertConstants.METAALERT_TYPE;
    SolrQuery solrQuery = new SolrQuery().setQuery(fullClause)
            .setFields("*", "[child parentFilter=" + metaalertTypeClause + " limit=999]")
            .addSort(Constants.GUID, SolrQuery.ORDER.asc); // Just do basic sorting to track where we are

    // Use Solr's Cursors to handle the paging, rather than doing it manually.
    List<SearchResult> allResults = new ArrayList<>();
    try {
        String cursorMark = CursorMarkParams.CURSOR_MARK_START;
        boolean done = false;
        while (!done) {
            solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
            QueryResponse rsp = solrClient.query(METAALERTS_COLLECTION, solrQuery);
            String nextCursorMark = rsp.getNextCursorMark();
            rsp.getResults().stream()
                    .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, null,
                            solrSearchDao.getAccessConfig().getIndexSupplier()))
                    .forEachOrdered(allResults::add);
            if (cursorMark.equals(nextCursorMark)) {
                done = true;
            }
            cursorMark = nextCursorMark;
        }
    } catch (IOException | SolrServerException e) {
        throw new InvalidSearchException("Unable to complete search", e);
    }

    SearchResponse searchResponse = new SearchResponse();
    searchResponse.setResults(allResults);
    searchResponse.setTotal(allResults.size());
    return searchResponse;
}

From source file:org.apache.nifi.processors.solr.GetSolr.java

License:Apache License

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {

    final ComponentLog logger = getLogger();
    final AtomicBoolean continuePaging = new AtomicBoolean(true);
    final SolrQuery solrQuery = new SolrQuery();

    try {/*from   ww w  .jav a 2s.c o  m*/
        if (id_field == null) {
            id_field = getFieldNameOfUniqueKey();
        }

        final String dateField = context.getProperty(DATE_FIELD).getValue();

        final Map<String, String> stateMap = new HashMap<String, String>();
        stateMap.putAll(context.getStateManager().getState(Scope.CLUSTER).toMap());

        solrQuery.setQuery("*:*");
        final String query = context.getProperty(SOLR_QUERY).getValue();
        if (!StringUtils.isBlank(query) && !query.equals("*:*")) {
            solrQuery.addFilterQuery(query);
        }
        final StringBuilder automatedFilterQuery = (new StringBuilder()).append(dateField).append(":[")
                .append(stateMap.get(STATE_MANAGER_FILTER)).append(" TO *]");
        solrQuery.addFilterQuery(automatedFilterQuery.toString());

        final List<String> fieldList = new ArrayList<String>();
        final String returnFields = context.getProperty(RETURN_FIELDS).getValue();
        if (!StringUtils.isBlank(returnFields)) {
            fieldList.addAll(Arrays.asList(returnFields.trim().split("[,]")));
            if (!fieldList.contains(dateField)) {
                fieldList.add(dateField);
                dateFieldNotInSpecifiedFieldsList.set(true);
            }
            for (String returnField : fieldList) {
                solrQuery.addField(returnField.trim());
            }
        }

        solrQuery.setParam(CursorMarkParams.CURSOR_MARK_PARAM, stateMap.get(STATE_MANAGER_CURSOR_MARK));
        solrQuery.setRows(context.getProperty(BATCH_SIZE).asInteger());

        final StringBuilder sortClause = (new StringBuilder()).append(dateField).append(" asc,")
                .append(id_field).append(" asc");
        solrQuery.setParam("sort", sortClause.toString());

        while (continuePaging.get()) {
            final QueryRequest req = new QueryRequest(solrQuery);
            if (isBasicAuthEnabled()) {
                req.setBasicAuthCredentials(getUsername(), getPassword());
            }

            logger.debug(solrQuery.toQueryString());
            final QueryResponse response = req.process(getSolrClient());
            final SolrDocumentList documentList = response.getResults();

            if (response.getResults().size() > 0) {
                final SolrDocument lastSolrDocument = documentList.get(response.getResults().size() - 1);
                final String latestDateValue = df.format(lastSolrDocument.get(dateField));
                final String newCursorMark = response.getNextCursorMark();

                solrQuery.setParam(CursorMarkParams.CURSOR_MARK_PARAM, newCursorMark);
                stateMap.put(STATE_MANAGER_CURSOR_MARK, newCursorMark);
                stateMap.put(STATE_MANAGER_FILTER, latestDateValue);

                FlowFile flowFile = session.create();
                flowFile = session.putAttribute(flowFile, "solrQuery", solrQuery.toString());

                if (context.getProperty(RETURN_TYPE).getValue().equals(MODE_XML.getValue())) {
                    if (dateFieldNotInSpecifiedFieldsList.get()) {
                        for (SolrDocument doc : response.getResults()) {
                            doc.removeFields(dateField);
                        }
                    }
                    flowFile = session.write(flowFile,
                            SolrUtils.getOutputStreamCallbackToTransformSolrResponseToXml(response));
                    flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(),
                            "application/xml");

                } else {
                    final RecordSetWriterFactory writerFactory = context.getProperty(RECORD_WRITER)
                            .asControllerService(RecordSetWriterFactory.class);
                    final RecordSchema schema = writerFactory.getSchema(null, null);
                    final RecordSet recordSet = SolrUtils.solrDocumentsToRecordSet(response.getResults(),
                            schema);
                    final StringBuffer mimeType = new StringBuffer();
                    flowFile = session.write(flowFile, new OutputStreamCallback() {
                        @Override
                        public void process(final OutputStream out) throws IOException {
                            try {
                                final RecordSetWriter writer = writerFactory.createWriter(getLogger(), schema,
                                        out);
                                writer.write(recordSet);
                                writer.flush();
                                mimeType.append(writer.getMimeType());
                            } catch (SchemaNotFoundException e) {
                                throw new ProcessException("Could not parse Solr response", e);
                            }
                        }
                    });
                    flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(),
                            mimeType.toString());
                }
                session.transfer(flowFile, REL_SUCCESS);
            }
            continuePaging.set(response.getResults().size() == Integer
                    .parseInt(context.getProperty(BATCH_SIZE).getValue()));
        }
        context.getStateManager().setState(stateMap, Scope.CLUSTER);
    } catch (SolrServerException | SchemaNotFoundException | IOException e) {
        context.yield();
        session.rollback();
        logger.error("Failed to execute query {} due to {}", new Object[] { solrQuery.toString(), e }, e);
        throw new ProcessException(e);
    } catch (final Throwable t) {
        context.yield();
        session.rollback();
        logger.error("Failed to execute query {} due to {}", new Object[] { solrQuery.toString(), t }, t);
        throw t;
    }
}

From source file:org.geotools.data.solr.SolrFeatureReader.java

License:Open Source License

/**
 * Creates the feature reader for SOLR store <br>
 * The feature reader use SOLR CURSOR to paginate request, so multiple SOLR query will be
 * executed//from   w w  w . j  a  v  a 2  s .c o  m
 * 
 * @param featureType the feature type to query
 * @param solrUrl the URL of SOLR server
 * @param solrQuery the SOLR query to execute
 * @param solrDataStore the SOLR store
 * @throws SolrServerException
 */
public SolrFeatureReader(SimpleFeatureType featureType, HttpSolrServer server, SolrQuery solrQuery,
        SolrDataStore solrDataStore) throws SolrServerException {
    this.featureType = featureType;
    this.solrQuery = solrQuery;
    this.wktReader = new WKTReader();
    this.solrDataStore = solrDataStore;
    this.pkey = solrDataStore.getPrimaryKey(featureType.getTypeName());

    this.builder = new SimpleFeatureBuilder(featureType);

    this.server = server;

    // Add always pk as field if not already present
    if (solrQuery.getFields() != null && !solrQuery.getFields().contains(pkey.getName())) {
        solrQuery.addField(pkey.getName());
    }

    // Can't use pagination with start, then first query for cursor mark of start
    if (solrQuery.getStart() != null && solrQuery.getStart() > 0) {
        cursorMark = getCursorMarkForStart(server, solrQuery);
    } else {
        cursorMark = CursorMarkParams.CURSOR_MARK_START;
    }
    solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
    QueryResponse rsp = server.query(solrQuery);
    if (this.solrDataStore.getLogger().isLoggable(Level.FINE)) {
        this.solrDataStore.getLogger().log(Level.FINE, "SOLR query done: " + solrQuery.toString());
    }
    this.solrDocIterator = rsp.getResults().iterator();
    nextCursorMark = rsp.getNextCursorMark();
    counter = 0;
}

From source file:org.geotools.data.solr.SolrFeatureReader.java

License:Open Source License

private String getCursorMarkForStart(HttpSolrServer server, SolrQuery solrQuery) throws SolrServerException {
    Integer prevRows = solrQuery.getRows();
    solrQuery.setRows(solrQuery.getStart());
    solrQuery.setStart(0);/* ww w .j  av  a2s .  c  o  m*/
    solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
    QueryResponse rsp = server.query(solrQuery);
    if (this.solrDataStore.getLogger().isLoggable(Level.FINE)) {
        this.solrDataStore.getLogger().log(Level.FINE, "SOLR query done: " + solrQuery.toString());
    }
    String nextC = rsp.getNextCursorMark();
    solrQuery.setRows(prevRows);
    return nextC;
}