List of usage examples for org.apache.solr.client.solrj SolrQuery setRequestHandler
public SolrQuery setRequestHandler(String qt)
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testEmptyMainQueryWithNestedMatchAll() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : \"bbb\" }"); SolrQuery query = new SolrQuery(); query.setParam("nested", "{!lucene} *:*"); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/* www . j a v a 2 s .c o m*/ }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testMultipleNestedQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : [\"bbb\", \"ccc\"] }"); SolrQuery query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ccc"); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);// w w w. j av a 2 s.c o m query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ddd"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(0, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testCurlyBracketInNestedQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); query.setParam("nested", "{!keyword} aaa : { bbb : ccc } "); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);//from ww w. j a v a 2 s . c o m query = new SolrQuery(); query.setParam("nested", "{!tree} { \"node\" : { \"query\" : \"ccc\" } }"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestURIQuery.java
License:Open Source License
@Test public void testTildeInURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://sw.deri.org/~aidanh/\", " + "\"_datatype_\" : \"uri\"" + " } }"); SolrQuery query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); // test uri trailing slash filter query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); }
From source file:com.sindicetech.siren.solr.qparser.TestURIQuery.java
License:Open Source License
@Test public void testEncodedURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller\", " + "\"_datatype_\" : \"uri\"" + " } }"); // testing search of plain URI search SolrQuery query = new SolrQuery(); query.setQuery("uri('http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); // testing search of decoded local name token query = new SolrQuery(); query.setQuery("Mller"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); }
From source file:com.sindicetech.siren.solr.response.TestSirenTransformer.java
License:Open Source License
@Test public void testTransformer() throws SolrServerException, IOException { SolrInputDocument document = new SolrInputDocument(); document.addField(ID_FIELD, "1"); document.addField(JSON_FIELD, json); getWrapper().add(document);/* w ww .j a va 2 s.co m*/ getWrapper().commit(); String queryStr = "{" + "\"twig\" : { " + "\"root\" : \"director\"," + "\"child\" : [{\"occur\":\"MUST\"," + "\"twig\": {" + "\"child\":[{\"occur\":\"MUST\"," + "\"twig\": {" + "\"root\":\"first_name\"," + "\"child\":[" + "{\"occur\":\"MUST\"," + "\"node\" : { \"query\" : \"Clint\" } " + "}" + "]" + "}" + "}" + "]" + "}" + "}" + ", {\"occur\" : \"MUST\", \"variable\" : {}}" + "]" + "}" + "}"; final SolrQuery query = new SolrQuery(); query.setQuery(queryStr); query.setRequestHandler("tree"); query.set(SirenParams.QF, JSON_FIELD); query.set("fl", "id,json,[sirenProjection]"); final String[] results = getWrapper().search(query, JSON_FIELD); assertEquals(1, results.length); assertEquals("{\"director\":{\"last_name\":\"Eastwood\",\"first_name\":\"Clint\",\"birth_date\":\"1930\"}}", results[0]); }
From source file:com.sindicetech.siren.solr.SolrServerWrapper.java
License:Open Source License
public String[] search(final String q, final String retrievedField, final String qt) throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setRequestHandler(qt); query.setQuery(q);/*ww w.j a v a 2 s . c o m*/ return this.search(query, retrievedField); }
From source file:com.temenos.interaction.commands.solr.TermsCommand.java
License:Open Source License
public Result execute(InteractionContext ctx) { MultivaluedMap<String, String> queryParams = ctx.getQueryParameters(); String entityName = ctx.getCurrentState().getEntityName(); try {//from ww w.ja v a2 s .c om String queryStr = queryParams.getFirst("q"); SolrQuery query = new SolrQuery(); query.setRequestHandler("/terms"); // query.setFields("id", "name", "mnemonic", "address", "postcode"); query.setQuery(queryStr); // TODO make these configurable query.addTermsField("name"); query.addTermsField("mnemonic"); query.setTermsPrefix(queryStr); query.setTermsSortString("count"); query.setTerms(true); query.setTermsLimit(10); QueryResponse rsp = solrServer.query(query); ctx.setResource(buildCollectionResource(entityName, "name", rsp.getTermsResponse().getTermMap())); return Result.SUCCESS; } catch (SolrServerException e) { logger.error("An unexpected error occurred while querying Solr", e); } return Result.FAILURE; }
From source file:com.zb.app.external.lucene.solr.utils.BaseSolrQueryConvert.java
License:Open Source License
protected static SolrQuery createSearchQuery(List<String> params, List<String> fiters, SearchQuery searchQuery) {/* w w w . j a va 2s . com*/ SolrQuery solrQuery = new SolrQuery(); String query = null; if (Argument.isEmpty(params)) { query = ("*:*"); } else { query = StringUtils.join(params, " AND "); if (!StringUtils.join(params.toArray()).contains("*")) { solrQuery.setRequestHandler("/browse"); } } if (Argument.isNotEmpty(fiters)) { solrQuery.setFilterQueries(StringUtils.join(fiters, " AND ")); } solrQuery.setQuery(query); solrQuery.setStart(searchQuery.getStart()); solrQuery.setRows(searchQuery.getRows()); if (StringUtils.isNotBlank(searchQuery.getSortFiled())) { solrQuery.addSort(searchQuery.getSortFiled(), searchQuery.getOrderBy()); } return solrQuery; }
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. * /*from w w w. j a v a 2 s . 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); } }