List of usage examples for org.apache.solr.client.solrj SolrQuery setQuery
public SolrQuery setQuery(String query)
From source file:digicom.pot.nlp.OpenNLPUtilTest.java
License:Apache License
@Test public void testFilters() { List<String> queryList = new ArrayList<String>(); queryList.add("CHEFS knife set"); queryList.add("CHEFS kitchen towels"); queryList.add("CHEFS red bath towels"); queryList.add("bowl set CHEFS 6 pcs"); queryList.add("U Tops"); queryList.add("U white Tops"); queryList.add("U red Tops under 10$"); queryList.add("U pink Tops less than 10$"); queryList.add("U pink Tops less than 10 usd"); queryList.add("red Kitchen Towels"); queryList.add("red Kitchen Towels under 15$"); queryList.add("silver Platinum Pets toys"); queryList.add("red Progear towel"); queryList.add("red Progear towel under 18$"); queryList.add("Dickies blue pant"); queryList.add("Dickies kids clothes"); queryList.add("black Dickies thermal inner"); queryList.add("Onyx U sweater"); queryList.add("Onyx sweater"); ColorHelper colorHelper = new ColorHelper(); BrandHelper bhelper = new BrandHelper(); PriceHelper pricehelper = new PriceHelper(); SearchQueryProcessor sqp = new SearchQueryProcessor(); SolrQuery query = new SolrQuery(); String queryString = null;// www.j av a 2s . c o m for (String document : queryList) { System.out.println("================================================="); /* * System.out.println("Colors : " + colorHelper.getColors(document, * extractor)); System.out.println("Brand : " + * bhelper.getBrands(document, extractor)); * System.out.println("Price : " + pricehelper.parseString(document, * extractor)); */ sqp.applyColorFilter(document, extractor, query); sqp.applyBrandFilter(document, extractor, query); queryString = sqp.applyPriceFilter(document, extractor, query); query.setQuery(queryString); System.out.println(query); } }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java
License:Apache License
public SolrDocumentList runQuery(String q, int results) throws SolrServerException { SolrQuery query = new SolrQuery(); query.setQuery(escapeQuery(q)); query.setRows(results);/*from w w w. j a va2 s.c o m*/ query.setFields("*", "score"); 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 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"); }// w w w . j av a 2 s .c o 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.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"); }// ww w . j a v a 2 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.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); 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);/*w w w . j a va 2s . c o m*/ } return docText; }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Executes a string query./* w ww . j a v a2 s . co m*/ * * @param q a query string. * @param numRet the maximum number of entries to return. * @return a list of documents, an object of the type {@link org.apache.solr.common.SolrDocumentList}. * @throws SolrServerException */ public SolrDocumentList runQuery(String q, int numRet) throws SolrServerException { SolrQuery query = new SolrQuery(); query.setQuery(q); query.setRows(numRet); query.setFields("*", "score"); 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 result fields. * /*from w ww.j a v a 2 s. c o 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 */ 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. * //from w ww . j a v a2s. 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 .j av a 2 s. c o 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 */ 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 string query./*from ww w. j a v a2 s . com*/ * * @param q a query string. * @param numRet the maximum number of entries to return. * @return a list of documents, an object of the type {@link org.apache.solr.common.SolrDocumentList}. * @throws SolrServerException * @throws IOException */ public SolrDocumentList runQuery(String q, int numRet) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setQuery(q); query.setRows(numRet); query.setFields("*", "score"); QueryResponse rsp = mServer.query(query, METHOD.POST); return rsp.getResults(); }