List of usage examples for org.apache.solr.client.solrj SolrQuery setParam
public SolrQuery setParam(String name, boolean value)
From source file:cz.zcu.kiv.eegdatabase.logic.search.FulltextSearchService.java
License:Apache License
/** * Given the input query, finds out the total count of full text results for each full text result type. * @param solrQuery The search query./*www . ja v a2 s . c om*/ * @return Map containg category-count pairs. */ public Map<String, Long> getCategoryFacets(String solrQuery) { SolrQuery query = new SolrQuery(solrQuery); query.setParam("fl", IndexField.UUID.getValue()); query.setHighlight(false); query.setFacet(true); query.addFacetField(IndexField.CLASS.getValue()); Map<String, Long> results = new HashMap<String, Long>(); QueryResponse response = null; try { response = solrServer.query(query); } catch (SolrServerException e) { log.error(e); } long totalCount = 0; List<FacetField> facets = response.getFacetFields(); for (FacetField field : facets) { log.info("count: " + field.getValueCount()); List<FacetField.Count> facetEntries = field.getValues(); for (FacetField.Count count : facetEntries) { long countValue = count.getCount(); results.put(count.getName(), countValue); log.info(count.getName() + ", " + countValue); totalCount += countValue; } } // add a "facet" for all results results.put(ResultCategory.ALL.getValue(), totalCount); return results; }
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 ww w . j av a 2s . 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:de.dlr.knowledgefinder.webapp.webservice.solr.query.AbstractSolrQueryFactory.java
License:Apache License
private void setSolrQueryParameter(SolrQuery solrQuery) { solrQuery.setHighlight(true);/* w w w . j av a2s . c o m*/ solrQuery.setParam("hl.fragsize", "0"); solrQuery.setParam("hl.preserveMulti", "true"); }
From source file:de.kp.ames.web.core.search.SearcherImpl.java
License:Open Source License
public String suggest(String request, String start, String limit) throws Exception { /*//from w w w .j av a 2 s . c om * Retrieve terms */ SolrQuery query = new SolrQuery(); query.setParam(CommonParams.QT, "/terms"); query.setParam(TermsParams.TERMS, true); query.setParam(TermsParams.TERMS_LIMIT, SearchConstants.TERMS_LIMIT); query.setParam(TermsParams.TERMS_FIELD, SearchConstants.TERMS_FIELD); query.setParam(TermsParams.TERMS_PREFIX_STR, request); QueryResponse response = solrProxy.executeQuery(query); NamedList<Object> terms = getTerms(response); JSONArray jTerms = getTermValues(SearchConstants.TERMS_FIELD, terms); /* * Render result for DataSource */ return jTerms.toString(); }
From source file:de.qaware.chronix.examples.server.ChronixClientExampleWithGenericTimeSeries.java
License:Apache License
public static void main(String[] args) { SolrClient solr = new HttpSolrClient.Builder().withBaseSolrUrl("http://localhost:8983/solr/chronix/") .build();//from w w w. j a v a 2 s . c om //Define a group by function for the time series records Function<GenericTimeSeries<Long, Double>, String> groupBy = ts -> ts.getAttribute("name") + "-" + ts.getAttribute("host"); //Define a reduce function for the grouped time series records. We use the average. BinaryOperator<GenericTimeSeries<Long, Double>> reduce = (ts1, ts2) -> merge(ts1, ts2, (y1, y2) -> (y1 + y2) / 2); //Instantiate a Chronix Client ChronixClient<GenericTimeSeries<Long, Double>, SolrClient, SolrQuery> chronix = new ChronixClient<>( new GenericTimeSeriesConverter(), new ChronixSolrStorage<>(200, groupBy, reduce)); //We want the maximum of all time series that metric matches *load*. SolrQuery query = new SolrQuery("name:*Load*"); query.setParam("cf", "metric{max}"); //The result is a Java Stream. We simply collect the result into a list. List<GenericTimeSeries<Long, Double>> maxTS = chronix.stream(solr, query).collect(Collectors.toList()); //Just print it out. LOGGER.info("Result for query {} is: {}", query, maxTS); }
From source file:de.qaware.chronix.examples.server.ChronixClientExampleWithMetricTimeSeries.java
License:Apache License
public static void main(String[] args) { SolrClient solr = new HttpSolrClient.Builder().withBaseSolrUrl("http://localhost:8983/solr/chronix/") .build();/*from w ww.j a v a 2 s. c om*/ //Define a group by function for the time series records Function<MetricTimeSeries, String> groupBy = ts -> ts.getName() + "-" + ts.attribute("host"); //Define a reduce function for the grouped time series records BinaryOperator<MetricTimeSeries> reduce = (ts1, ts2) -> { if (ts1 == null || ts2 == null) { return new MetricTimeSeries.Builder("empty", "metric").build(); } ts1.addAll(ts2.getTimestampsAsArray(), ts2.getValuesAsArray()); return ts1; }; //Instantiate a Chronix Client ChronixClient<MetricTimeSeries, SolrClient, SolrQuery> chronix = new ChronixClient<>( new MetricTimeSeriesConverter(), new ChronixSolrStorage<>(200, groupBy, reduce)); //We want the maximum of all time series that metric matches *load*. SolrQuery query = new SolrQuery("name:*Load*"); query.setParam("cf", "metric{max}"); //The result is a Java Stream. We simply collect the result into a list. List<MetricTimeSeries> maxTS = chronix.stream(solr, query).collect(Collectors.toList()); //Just print it out. LOGGER.info("Result for query {} is: {}", query, prettyPrint(maxTS)); }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java
License:Apache License
public SolrDocumentList runQuery(String q, int results, String type, String mm, String Geneboost, String Diseboost, String Verbboost) throws SolrServerException { SolrQuery query = new SolrQuery(); if (type.equals("dismax")) { query.setParam("defType", "edismax"); query.setParam("qf", "text"); query.setParam("mm", mm); query.setParam("pf", "text^100"); }/*from w ww . j a va 2s. c om*/ query.setQuery(getBoosts(escapeQuery(q), Geneboost, Diseboost, Verbboost)); query.setRows(results); query.setFields("*", "score"); //can also try nested query for different boosts of phrase in text //q=revised+AND+book+AND+_query_:"{!dismax qf=title pf=title^10 v=$qq}"&qq=revised+book System.out.println(query.toString()); QueryResponse rsp = server.query(query); return rsp.getResults(); }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java
License:Apache License
public SolrDocumentList runQuery(String q, int results, String type, String Geneboost, String Diseboost, String Verbboost) throws SolrServerException { SolrQuery query = new SolrQuery(); if (type.equals("dismax")) { query.setParam("defType", "edismax"); query.setParam("qf", "text"); query.setParam("pf", "text^100"); }//from w w w .j av a2 s .co m query.setQuery(getBoosts(escapeQuery(q), Geneboost, Diseboost, Verbboost)); query.setRows(results); query.setFields("*", "score"); //can also try nested query for different boosts of phrase in text //q=revised+AND+book+AND+_query_:"{!dismax qf=title pf=title^10 v=$qq}"&qq=revised+book System.out.println(query.toString()); QueryResponse rsp = server.query(query); return rsp.getResults(); }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Executes a query, additionally allows to specify the default field, the filter query, AND result fields. * //from w w w . java 2 s. c o m * @param q a query string. * @param defaultField a default field name (or null). * @param fieldList a list of field names. * @param filterQuery a name of the filter query that can be applied without changing scores (or null). * @param results the maximum number of entries to return. * * @return a list of documents, which is an object of the type {@link org.apache.solr.common.SolrDocumentList}. * @throws SolrServerException */ public SolrDocumentList runQuery(String q, String defaultField, List<String> fieldList, String filterQuery, int results) throws SolrServerException { SolrQuery query = new SolrQuery(); query.setQuery(q); if (filterQuery != null) query.setParam("fq", filterQuery); if (defaultField != null) query.setParam("df", defaultField); query.setRows(results); query.setFields(fieldList.toArray(new String[1])); QueryResponse rsp = mServer.query(query, METHOD.POST); return rsp.getResults(); }
From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java
License:Apache License
/** * Executes a query, additionally allows to specify the default field, the filter query, AND result fields. * // ww w. j av a2s . co m * @param q a query string. * @param defaultField a default field name (or null). * @param fieldList a list of field names. * @param filterQuery a name of the filter query that can be applied without changing scores (or null). * @param results the maximum number of entries to return. * * @return a list of documents, which is an object of the type {@link org.apache.solr.common.SolrDocumentList}. * @throws SolrServerException * @throws IOException */ public SolrDocumentList runQuery(String q, String defaultField, List<String> fieldList, String filterQuery, int results) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setQuery(q); if (filterQuery != null) query.setParam("fq", filterQuery); if (defaultField != null) query.setParam("df", defaultField); query.setRows(results); query.setFields(fieldList.toArray(new String[1])); QueryResponse rsp = mServer.query(query, METHOD.POST); return rsp.getResults(); }