List of usage examples for org.apache.solr.client.solrj SolrQuery setFields
public SolrQuery setFields(String... fields)
From source file:dk.statsbiblioteket.doms.licensemodule.solr.AbstractSolrJClient.java
public ArrayList<String> filterIds(ArrayList<String> ids, String queryPartAccess) throws Exception { if (ids == null || ids.size() == 0) { return new ArrayList<String>(); }//from w w w . j av a 2s.c o m String queryStr = makeAuthIdPart(ids); log.debug("query:" + queryStr); SolrQuery query = new SolrQuery(queryStr); query.setFilterQueries(queryPartAccess); log.debug("filter:" + queryPartAccess); query.setFields(filterField); //only this field is used from resultset query.setRows(Math.min(10000, ids.size() * 200)); // Powerrating... each page can have max 200 segments (rare).. with 20 pages query this is 4000.. query.set("facet", "false"); // Must be parameter set, because this java method does NOT work: query.setFacet(false); QueryResponse response = solrServer.query(query); ArrayList<String> filteredIds = getIdsFromResponse(response); return filteredIds; }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java
License:Apache License
public String getDocText(String id) throws SolrServerException { String q = "id:" + id; SolrQuery query = new SolrQuery(); query.setQuery(q);// w w w . j a va 2 s. co m query.setFields("text"); QueryResponse rsp = server.query(query); String docText = ""; if (rsp.getResults().getNumFound() > 0) { @SuppressWarnings({ "unchecked", "rawtypes" }) ArrayList<String> results = (ArrayList) rsp.getResults().get(0).getFieldValues("text"); docText = results.get(0); } return docText; }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Executes a query, additionally allows to specify result fields. * /*from w ww . j a v a 2s .c om*/ * @param q a query string. * @param fieldList a list of field names. * @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, List<String> fieldList, int results) throws SolrServerException { SolrQuery query = new SolrQuery(); query.setQuery(q); 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.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Executes a query, additionally allows to specify the default field, the filter query, AND result fields. * // w w w . j av a 2s . 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.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Reads a value of a single- or multi-value text field from a SOLR server. * /*from w w w . java2 s. c om*/ * @param docId a document ID. * @param idField a name of the ID field. * @param textFieldName a name of the text field whose value we need to obtain. * @return an array of field values, if the field is single-value, the array * contains only one entry. * @throws SolrServerException */ public ArrayList<String> getFieldText(String docId, String idField, String textFieldName) throws SolrServerException { String q = idField + ":" + docId; SolrQuery query = new SolrQuery(); query.setQuery(q); query.setFields(textFieldName); QueryResponse rsp = mServer.query(query); ArrayList<String> docText = null; if (rsp.getResults().getNumFound() > 0) { Object o = rsp.getResults().get(0).getFieldValues(textFieldName); if (o instanceof String) { docText = new ArrayList<String>(); docText.add((String) o); } else { @SuppressWarnings({ "unchecked" }) ArrayList<String> results = (ArrayList<String>) o; docText = results; } } return docText; }
From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java
License:Apache License
/** * Executes a query, additionally allows to specify result fields. * /* w w w. j a v a 2 s. co m*/ * @param q a query string. * @param fieldList a list of field names. * @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, List<String> fieldList, int results) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setQuery(q); 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. * /*from w w w . j a v a 2 s . c om*/ * @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(); }
From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java
License:Apache License
/** * Reads a value of a single- or multi-value text field from a SOLR server. * /*from w w w .j a v a 2 s . co m*/ * @param docId a document ID. * @param idField a name of the ID field. * @param textFieldName a name of the text field whose value we need to obtain. * @return an array of field values, if the field is single-value, the array * contains only one entry. * @throws SolrServerException * @throws IOException */ public ArrayList<String> getFieldText(String docId, String idField, String textFieldName) throws SolrServerException, IOException { String q = idField + ":" + docId; SolrQuery query = new SolrQuery(); query.setQuery(q); query.setFields(textFieldName); QueryResponse rsp = mServer.query(query); ArrayList<String> docText = null; if (rsp.getResults().getNumFound() > 0) { Object o = rsp.getResults().get(0).getFieldValues(textFieldName); if (o instanceof String) { docText = new ArrayList<String>(); docText.add((String) o); } else { @SuppressWarnings({ "unchecked" }) ArrayList<String> results = (ArrayList<String>) o; docText = results; } } return docText; }
From source file:edu.cmu.lti.oaqa.core.provider.solr.SolrWrapper.java
License:Apache License
/** Added overloaded method for specifying field list**/ public SolrDocumentList runQuery(String q, List<String> fieldList, int results) throws SolrServerException { SolrQuery query = new SolrQuery(); query.setQuery(escapeQuery(q));/*w w w .j a v a 2 s. co m*/ query.setRows(results); query.setFields(fieldList.toArray(new String[1])); QueryResponse rsp = server.query(query, METHOD.POST); return rsp.getResults(); }
From source file:edu.harvard.liblab.ecru.rs.ResourceUtils.java
License:Open Source License
public static SolrQuery createSolrQuery(String q, List<String> fqs, String fl, String start, String rows, HashMap<String, List<String>> facetMap, String sort) { SolrQuery query = new SolrQuery(); if (q == null || q.trim().isEmpty()) { q = QUERY_ALL;// w w w. ja va2s . c o m } query.setQuery(q); if (fqs != null && !fqs.isEmpty()) { query.setFilterQueries(fqs.toArray(new String[fqs.size()])); } try { Integer s = new Integer(start); query.setStart(s); } catch (NumberFormatException e) { if (start != null) System.out.println("start not integer: " + start); } try { Integer r = new Integer(rows); query.setRows(r); } catch (NumberFormatException e) { if (rows != null) System.out.println("rows not integer: " + rows); } if (fl != null && !fl.isEmpty()) { if (fl.indexOf("type") < 0) { fl += ",type"; } String[] fields = fl.split(","); for (int i = 0; i < fields.length; i++) { fields[i] = fields[i].trim(); } query.setFields(fields); } if (sort != null && !sort.trim().isEmpty()) { String[] sortArr = sort.split(","); ArrayList<SortClause> clauses = new ArrayList<SortClause>(); for (String s : sortArr) { if (!s.isEmpty()) { String[] sc = s.split(" "); String v = sc[0]; String order = "asc"; if (sc.length == 2) { order = sc[1]; } clauses.add(new SortClause(v, (order.equals("asc") ? ORDER.asc : ORDER.desc))); } } query.setSorts(clauses); } query = addFacetsToQuery(query, facetMap); return query; }