List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery()
From source file:cz.zcu.kiv.eegdatabase.logic.search.FulltextSearchService.java
License:Apache License
/** * Gets the number of all documents matching the query. * @param queryString The query string.//w w w . ja v a2 s . c o m * @return The number of all documents matching the query. */ public int getTotalNumberOfDocumentsForQuery(String queryString, ResultCategory category) { SolrQuery q = new SolrQuery(); q.setQuery(queryString); if (category != null && !category.equals(ResultCategory.ALL)) { q.setFilterQueries(IndexField.CLASS.getValue() + ":\"" + category.getValue() + "\""); } q.setRows(0); // don't actually request any data try { return (int) solrServer.query(q).getResults().getNumFound(); } catch (SolrServerException e) { log.error(e); e.getCause().printStackTrace(); } return 0; }
From source file:datacite.oai.provider.service.MDSSearchServiceSolrImpl.java
License:Open Source License
@Override public DatasetRecordBean getDatasetByID(String id) throws ServiceException { SolrQuery query = new SolrQuery(); query.setQuery("dataset_id:" + id); try {/*ww w. j a va2s .c o m*/ QueryResponse response = solrServer.query(query); if (response.getResults().isEmpty()) return null; SolrDocument doc = response.getResults().get(0); return convertToRecord(doc); } catch (Exception e) { throw new ServiceException(e); } }
From source file:datacite.oai.provider.service.MDSSearchServiceSolrImpl.java
License:Open Source License
static SolrQuery constructSolrQuery(Date updateDateFrom, Date updateDateTo, String setspec, int offset, int length) throws ServiceException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(length);/*from w w w. j av a 2 s. c o m*/ query.setStart(offset); query.setSortField("updated", ORDER.asc); setspec = StringUtils.trimToEmpty(setspec); if (setspec.contains(Constants.Set.BASE64_PART_DELIMITER)) { String split[] = setspec.split(Constants.Set.BASE64_PART_DELIMITER, 2); setspec = split[0]; String base64 = split[1]; String solrfilter = new String(Base64.decodeBase64(base64)); logger.info("decoded base64 setspec: " + solrfilter); solrfilter = solrfilter.replaceAll("^[?&]+", ""); List<NameValuePair> params = URLEncodedUtils.parse(solrfilter, Charset.defaultCharset()); for (NameValuePair param : params) { String name = param.getName(); String value = param.getValue(); if (name.equals("q")) query.setQuery(value); else if (name.equals("fq")) query.addFilterQuery(value); else throw new ServiceException("parameter '" + name + "' is not supported"); } } if (setspec != null && setspec.trim().length() > 0) { setspec = setspec.trim().toUpperCase(); String field = setspec.contains(".") ? "datacentre_symbol" : "allocator_symbol"; query.addFilterQuery(field + ":" + setspec); } String from = dateFormat.format(updateDateFrom); String to = dateFormat.format(updateDateTo); query.addFilterQuery("updated:[" + from + " TO " + to + "]"); query.setParam(CommonParams.QT, "/api"); return query; }
From source file:datacite.oai.provider.service.MDSSearchServiceSolrImpl.java
License:Open Source License
@Override public Pair<List<SetRecordBean>, Integer> getSets() throws ServiceException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(0);//from w w w.j a v a 2 s. c o m query.setFacet(true); query.setFacetLimit(-1); query.addFacetField("allocator_facet", "datacentre_facet"); try { QueryResponse response = solrServer.query(query); SortedSet<String> facetValues = new TreeSet<String>(); for (FacetField facet : response.getFacetFields()) { for (Count count : facet.getValues()) { facetValues.add(count.getName()); } } ArrayList<SetRecordBean> sets = new ArrayList<SetRecordBean>(); for (String facetValue : facetValues) { String[] parts = facetValue.split(" - ", 2); String symbol = parts[0]; String name = parts[1]; sets.add(new SetRecordBean(symbol, name)); } return new Pair<List<SetRecordBean>, Integer>(sets, sets.size()); } catch (Exception e) { throw new ServiceException(e); } }
From source file:ddf.catalog.cache.solr.impl.DynamicSchemaResolver.java
License:Open Source License
/** * Adds the fields that are already in the server to the cache. This method should be called * once the SolrServer is up to ensure the cache is synchronized with the server. * //w w w. j a v a 2s . c o m * @param server * the SolrServer we are working with */ public void addFieldsFromServer(SolrServer server) { if (server == null) { LOGGER.warn("Server is null, could not add fields to cache."); return; } SolrQuery query = new SolrQuery(); // numterms=0 means retrieve everything (regular or dynamic fields) query.add("numterms", "0"); /* * Adding this request handler allows us to query the schema dynamically. The name of the * request handler is provided by the schema.xml. If the name is changed in the schema.xml, * then this value must be changed as well. */ query.setRequestHandler("/admin/luke"); QueryResponse response = null; try { response = server.query(query); for (Entry<String, ?> e : ((SimpleOrderedMap<?>) (response.getResponse().get(FIELDS_KEY)))) { fieldsCache.add(e.getKey()); } } catch (SolrServerException e) { LOGGER.warn("Could not update cache for field names.", e); } catch (SolrException e) { LOGGER.warn("Could not update cache for field names.", e); } }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery propertyIsEqualTo(String propertyName, Date exactDate) { String mappedPropertyName = getMappedPropertyName(propertyName, AttributeFormat.DATE, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":" + QUOTE + dateFormat.format(exactDate) + QUOTE); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery buildDateQuery(String propertyName, String startCondition, String startDate, String endDate, String endCondition) {// w ww . ja va 2 s . c om SolrQuery query = new SolrQuery(); query.setQuery(" " + getMappedPropertyName(propertyName, AttributeFormat.DATE, false) + startCondition + startDate + TO + endDate + endCondition); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getGreaterThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":[ " + literal.toString() + TO + "* ] "); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getEqualToQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":" + literal.toString()); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getGreaterThanQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":{ " + literal.toString() + TO + "* ] "); return query; }