List of usage examples for org.apache.solr.client.solrj SolrQuery setStart
public SolrQuery setStart(Integer start)
From source file:org.craftercms.commerce.server.solr.AbstractSolrCRUDService.java
License:Open Source License
public ServiceResponse<T> findByQuery(String query, int offset, int maxResults, String... facet) throws CrafterCommerceException { try {//w w w.j ava 2s .c o m String solrQueryStr = queryConverter.toSolrQuery(query); SolrQuery solrQuery = new SolrQuery(solrQueryStr); solrQuery.setStart(offset); solrQuery.setRows(maxResults); // construct facet parameters if (facet.length > 0) { solrQuery.setFacet(true); solrQuery.setFacetMinCount(2); // only get the facet if there are 2 or more values for (String _facet : facet) { solrQuery.addFacetField(_facet); } } // execute Solr query QueryResponse response = solrServer.query(solrQuery); Set<T> entities = toEntities(response); Set<Facet> facets = toFacets(response); // create the service response ServiceResponse<T> serviceResponse = new ServiceResponse<T>(); serviceResponse.setSuccess(true); serviceResponse.setEntities(entities); serviceResponse.setCount(response.getResults().getNumFound()); serviceResponse.setFacets(facets); String msg = ReturnMessageProvider.findByQueryMessage(getTypeArgument(), query, entities.size()); serviceResponse.setMessage(msg); // return the response return serviceResponse; } catch (Exception e) { LOGGER.error("Failed to find entities by query for query = " + query, e); return new ServiceResponse<T>(getTypeArgument(), false, e.getMessage()); } }
From source file:org.dataconservancy.dcs.access.impl.solr.DcsSolrSearcher.java
License:Apache License
public QueryResponse search(String query, int offset, int maxmatches, String... params) throws SolrServerException { SolrQuery q = new SolrQuery(query); q.setStart(offset); q.setRows(maxmatches);/*w ww. java 2 s .co m*/ for (int i = 0; i < params.length;) { String name = params[i++]; String val = params[i++]; q.setParam(name, val); } return server.query(q); }
From source file:org.dataconservancy.dcs.index.dcpsolr.SeadSolrService.java
License:Apache License
@Override public QueryResponse search(String query, int offset, int matches, String... params) throws SolrServerException { SolrQuery q = new SolrQuery(query); q.setStart(offset); q.setRows(matches);/* www .j av a 2 s .c om*/ for (int i = 0; i < params.length;) { System.out.println(i + " " + params[i] + " length=" + params.length); if (params[i].equalsIgnoreCase("facet.field")) //if condition checks and enables faceted search { i++; String[] facets = params[i++].split(","); for (int j = 0; j < facets.length; j++) { System.out.println(i + " " + j + " " + facets[j]); q.addFacetField(facets[j]); } } if (i == params.length) break; if (params[i].equalsIgnoreCase("sort")) //if condition checks and enables sort { i++; String[] sortFields = params[i++].split(","); for (int j = 0; j < sortFields.length; j++) { j++; if (sortFields[j].equalsIgnoreCase("asc")) q.addSortField(sortFields[j - 1], SolrQuery.ORDER.asc); else q.addSortField(sortFields[j - 1], SolrQuery.ORDER.desc); } } else { String name = params[i++]; String val = params[i++]; q.setParam(name, val); } } QueryResponse resp = server().query(q); return resp; }
From source file:org.dataconservancy.dcs.index.dcpsolr.SolrService.java
License:Apache License
/** * @param query// ww w . j a v a 2 s. c o m * @param offset * @param matches * @param params * name,value pairs of Solr params * @return * @throws SolrServerException */ public QueryResponse search(String query, int offset, int matches, String... params) throws SolrServerException { SolrQuery q = new SolrQuery(query); q.setStart(offset); q.setRows(matches); for (int i = 0; i < params.length;) { String name = params[i++]; String val = params[i++]; q.setParam(name, val); } return server.query(q); }
From source file:org.dataone.proto.trove.mn.dao.v1.SolrLogIndexer.java
License:Apache License
/** * Pull solr query field parameters from a Properties file and use them to issue a solr query. * * The solr query results are transformed into a Log object and returned. * * The following fields are currently supported and passed through to the solr log index as a query * * fromDate (Types.DateTime) Records with time stamp greater than or equal to (>=) this value will be returned. * Transmitted as a URL query parameter, and so must be escaped accordingly. toDate (Types.DateTime) Records with * a time stamp less than this value will be returned. If not specified, then defaults to now. Transmitted as a URL * query parameter, and so must be escaped accordingly. event (Types.Event) Return only log records for the * specified type of event. Default is all. Transmitted as a URL query parameter, and so must be escaped * accordingly. pidFilter (string) Return only log records for identifiers that start with the supplied identifier * string. Support for this parameter is optional and MAY be ignored by the Member Node implementation with no * warning. Transmitted as a URL query parameter, and so must be escaped accordingly. start=0 (integer) Optional * zero based offset from the first record in the set of matching log records. Used to assist with paging the * response. Transmitted as a URL query parameter, and so must be escaped accordingly. count=1000 (integer) The * maximum number of log records that should be returned in the response. The Member Node may return fewer and the * caller should check the total in the response to determine if further pages may be retrieved. Transmitted as a * URL query parameter, and so must be escaped accordingly. * * * * * @param query/*from w ww .j a v a2s. c om*/ * @return Log * @throws org.apache.commons.configuration.ConfigurationException * @throws java.io.IOException * @throws org.apache.solr.client.solrj.SolrServerException */ @Override public Log search(Properties query) throws ConfigurationException, IOException, SolrServerException { // since this is the implementation assume the input to be a properties file. Configuration apacheConfiguration = getApacheConfiguration(query); List<LogEntrySolrItem> outputList = new ArrayList(); // may not have to initialize Log log = new Log(); SolrQuery queryParams = new SolrQuery(); queryParams.setQuery(queryStringBuilder(apacheConfiguration)); queryParams.setSortField("dateAggregated", SolrQuery.ORDER.desc); if (apacheConfiguration.containsKey("start")) { queryParams.setStart(apacheConfiguration.getInt("start")); } else { queryParams.setStart(0); } if (apacheConfiguration.containsKey("count")) { queryParams.setRows(apacheConfiguration.getInt("count")); } else { queryParams.setRows(defaultCount); } QueryResponse queryResponse = solrServer.query(queryParams); queryResponse.getResults(); List<LogEntrySolrItem> logEntryList = queryResponse.getBeans(LogEntrySolrItem.class); for (LogEntrySolrItem lesi : logEntryList) { log.addLogEntry(lesi.getLogEntry()); } log.setTotal(Long.valueOf(queryResponse.getResults().getNumFound()).intValue()); log.setStart(Long.valueOf(queryResponse.getResults().getStart()).intValue()); log.setCount(logEntryList.size()); return log; }
From source file:org.dataone.proto.trove.mn.dao.v1.SolrQueryIndexer.java
License:Apache License
@Override public ObjectList search(Properties query) throws Exception { // since this is the implementation assume the input to be a properties file. Configuration apacheConfiguration = getApacheConfiguration(query); ObjectList objectList = new ObjectList(); SolrQuery queryParams = new SolrQuery(); queryParams.setQuery(queryStringBuilder(apacheConfiguration)); queryParams.setSortField("id", SolrQuery.ORDER.desc); if (apacheConfiguration.containsKey("start")) { queryParams.setStart(apacheConfiguration.getInt("start")); } else {//from w w w .j a va 2 s . c o m queryParams.setStart(0); } if (apacheConfiguration.containsKey("count")) { queryParams.setRows(apacheConfiguration.getInt("count")); } else { queryParams.setRows(defaultCount); } QueryResponse queryResponse = solrServer.query(queryParams); queryResponse.getResults(); List<ObjectInfoSolrItem> objectInfoList = queryResponse.getBeans(ObjectInfoSolrItem.class); for (ObjectInfoSolrItem lesi : objectInfoList) { objectList.addObjectInfo(lesi.getObjectInfo()); } objectList.setTotal(Long.valueOf(queryResponse.getResults().getNumFound()).intValue()); objectList.setStart(Long.valueOf(queryResponse.getResults().getStart()).intValue()); objectList.setCount(objectInfoList.size()); return objectList; }
From source file:org.dbflute.solr.bhv.AbstractSolrBehavior.java
License:Apache License
/** * Retrieve count of the number of entities matched to the specified query condition. * @param cbLambda ConditionBean callback function (NotNull) * @return Total number of entities matched to query condition *//* w w w . java2 s.c o m*/ public int selectCount(SolrCBCall<CB> cbLambda) { CB cb = createCB(cbLambda); SolrQuery query = cb.buildSolrQuery(); query.setStart(0); query.setRows(0); if (logger.isDebugEnabled()) { logger.debug("cb={}", cb); } try { QueryResponse rsp = getSlaveSolrClient().query(query, METHOD.POST); return (int) rsp.getResults().getNumFound(); } catch (SolrServerException | IOException e) { throw new SolrException("Failed to Solr of access.", e); } }
From source file:org.dbflute.solr.bhv.AbstractSolrBehavior.java
License:Apache License
/** * Retrieve entities by faceted search./*w w w . j a va 2 s .c o m*/ * @param cbLambda ConditionBean callback function * @return List of faceted search result (NotNull) */ public SolrFacetResultBean selectFacetQuery(SolrCBCall<CB> cbLambda) { CB cb = createCB(cbLambda); SolrQuery query = cb.buildSolrQuery(); query.setStart(0); query.setRows(0); if (logger.isDebugEnabled()) { logger.debug("cb={}", cb); } try { QueryResponse rsp = getSlaveSolrClient().query(query, METHOD.POST); SolrFacetResultBean resultBean = new SolrFacetResultBean(); resultBean.setFacetResult(rsp.getFacetQuery()); resultBean.setFacetFieldList(rsp.getFacetFields()); resultBean.setQueryString(query.toString()); resultBean.setQueryTime(rsp.getQTime()); return resultBean; } catch (SolrServerException | IOException e) { throw new SolrException("Failed to Solr of access.", e); } }
From source file:org.dbflute.solr.cbean.AbstractSolrConditionBean.java
License:Apache License
@Override public SolrQuery buildSolrQuery() { SolrQuery query = new SolrQuery(); if (this.isSpecified()) { query.setFields(this.getSpecifyFields()); } else {/*from w ww. j a v a 2 s . c o m*/ query.setFields(this.getAllFields()); } if (this.isUseFilterQuery()) { query.setQuery(this.getMinimumQuery()); query.setFilterQueries(this.getQueryArray()); } else { query.setQuery(this.getQueryString()); String[] filterQueryArray = this.getFilterQueryArray(); if (filterQueryArray != null && filterQueryArray.length != 0) { query.setFilterQueries(this.getFilterQueryArray()); } } if (this.isUseSort()) { for (SortClause sortClause : this.getSolrSortClauseList()) { query.addSort(sortClause); } } for (SolrQueryBean queryBean : this.getFacetQueryList()) { query.addFacetQuery(queryBean.getQueryString()); } SolrSpecification facetSpecifyBean = getFacetSpecification(); if (facetSpecifyBean.getSpecifyFields().length > 0) { query.addFacetField(facetSpecifyBean.getSpecifyFields()); } query.setStart(this.getPageStart()); query.setRows(this.getPageSize()); return query; }
From source file:org.dspace.app.cris.batch.ScriptIndexNetwork.java
private static boolean checkAvailableData(String connection, VisualizationGraphSolrService service) throws SearchServiceException { String query = "type:" + connection; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);/* www . j a va2s. c o m*/ solrQuery.setStart(0); solrQuery.setRows(0); QueryResponse rsp = service.search(solrQuery); SolrDocumentList docs = rsp.getResults(); if (docs != null) { if (docs.getNumFound() > 0) { return true; } } return false; }