List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery(String q)
From source file:com.ibm.watson.developer_cloud.professor_languo.pipeline.primary_search.RetrieveAndRankSearcher.java
License:Open Source License
public Collection<CandidateAnswer> performSearch(String query, int numAns) throws SearchException { SolrQuery featureSolrQuery = new SolrQuery(query); // Specify the request handler for the feature query featureSolrQuery.setRequestHandler(request_handler); // Specify parameters for the response featureSolrQuery.setParam(RetrieveAndRankSearcherConstants.FIELD_LIST_PARAM, RetrieveAndRankSearcherConstants.ID_FIELD + "," + RetrieveAndRankSearcherConstants.FEATURE_VECTOR_FIELD + "," + IndexDocumentFieldName.SERIALIZED_THREAD.toString()); featureSolrQuery.setRows(numAns);//from w ww . j ava 2s.co m // Make the request final QueryRequest featureRequest = new QueryRequest(featureSolrQuery); QueryResponse featureResponse = null; try { featureResponse = processSolrRequest(featureRequest); } catch (IOException | SolrServerException | InterruptedException e) { log.error(e.toString(), e); throw new SearchException(e); } return responseToCollection(featureResponse); }
From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.RetrieveAndRankSolrHttpClientExample.java
License:Open Source License
/** * Search for the document indexed earlier. *///from w ww . j av a 2 s .c om private static void searchAllDocs() throws IOException { System.out.println("Searching for document..."); final SolrQuery query = new SolrQuery(QUERY_MATCHING_ANY_DOCUMENT); try { final QueryResponse response = watsonSolrClient.query(COLLECTION_NAME, query); System.out.println("Found " + response.getResults().size() + " documents!"); System.out.println(response); } catch (final SolrServerException e) { throw new RuntimeException("Failed to search!", e); } }
From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.utils.SolrUtils.java
License:Open Source License
/** * Create and process a Solr query//from w w w .jav a 2s . c o m * * @param query the query * @param featureVector the feature vector * @return the query response * @throws IOException Signals that an I/O exception has occurred. * @throws SolrServerException the Solr server exception * @throws InterruptedException the interrupted exception */ private QueryResponse solrRuntimeQuery(String query, boolean featureVector) throws IOException, SolrServerException, InterruptedException { SolrQuery featureSolrQuery = new SolrQuery(query); if (featureVector) { featureSolrQuery.setRequestHandler(FCSELECT_REQUEST_HANDLER); // add the ranker id - this tells the plugin to re-reank the results in a single pass featureSolrQuery.setParam(RANKER_ID, rankerId); } // bring back the id, score, and featureVector for the feature query featureSolrQuery.setParam(FIELD_LIST_PARAM, ID_FIELD, SCORE_FIELD, FEATURE_VECTOR_FIELD); // need to ask for enough rows to ensure the correct answer is included in the resultset featureSolrQuery.setRows(1000); QueryRequest featureRequest = new QueryRequest(featureSolrQuery, METHOD.POST); return processSolrRequest(featureRequest); }
From source file:com.ibm.watson.retrieveandrank.app.rest.RetrieveAndRankProxyResource.java
License:Open Source License
private static QueryResponse solrRuntimeQuery(String query, boolean featureVector) throws IOException, SolrServerException, InterruptedException { // boolean headersPrinted = false; final SolrQuery featureSolrQuery = new SolrQuery(query); // specify the fcselect request handler for the feature query if (featureVector) { featureSolrQuery.setRequestHandler(FCSELECT_REQUEST_HANDLER); // add the ranker id - this tells the plugin to re-reank the results in a single pass featureSolrQuery.setParam("ranker_id", ranker_id); }//from w ww . ja v a2s .c o m // bring back the id, score, and featureVector for the feature query featureSolrQuery.setParam(FIELD_LIST_PARAM, ID_FIELD, SCORE_FIELD, FEATURE_VECTOR_FIELD); // need to ask for enough rows to ensure the correct answer is included in the resultset featureSolrQuery.setRows(1000); final QueryRequest featureRequest = new QueryRequest(featureSolrQuery, METHOD.POST); // this leverages the plugin final QueryResponse featureResponse = processSolrRequest(featureRequest); return featureResponse; }
From source file:com.ifactory.press.db.solr.processor.FieldMergingProcessorTest.java
License:Apache License
@Test public void testMergeFields() throws Exception { SolrInputDocument doc = new SolrInputDocument(); doc.addField("uri", "/doc/1"); doc.addField(TITLE_FIELD, TITLE);//from w w w .j a v a2s. co m doc.addField(TEXT_FIELD, TEST); solr.add(doc); solr.commit(false, true, true); // basic check that the document was inserted SolrQuery solrQuery = new SolrQuery("uri:\"/doc/1\""); QueryResponse resp = solr.query(solrQuery); SolrDocumentList docs = resp.getResults(); assertEquals(1, docs.size()); SolrDocument result = docs.get(0); assertEquals("/doc/1", result.get("uri")); // text field is tokenized, analyzed: assertQueryCount(1, TEXT_FIELD + ":intentional"); // title field is tokenized, analyzed: assertQueryCount(1, TITLE_FIELD + ":era"); assertQueryCount(1, TITLE_FIELD + ":dawning"); for (TermsResponse.Term term : getTerms(TITLE_FIELD)) { assertNotEquals(TITLE, term.getTerm()); } HashSet<String> words = new HashSet<String>(Arrays.asList(TEST.split(" "))); int numWords = words.size(); List<TermsResponse.Term> terms; terms = getTerms("catchall"); // one term for each word in text + 1 for the title assertEquals("Wrong number of terms in catchall field", numWords + 1, terms.size()); boolean found = false; for (TermsResponse.Term term : terms) { if (TITLE.equals(term.getTerm())) { found = true; } } assertTrue("title not found in catchall terms list", found); }
From source file:com.ifactory.press.db.solr.processor.FieldMergingProcessorTest.java
License:Apache License
private void assertQueryCount(int count, String query) throws SolrServerException { SolrQuery solrQuery = new SolrQuery(query); QueryResponse resp = solr.query(solrQuery); SolrDocumentList docs = resp.getResults(); assertEquals(count, docs.size());//from ww w . j a v a 2 s . c om }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
@Test /**//w w w.j a v a2s.co m * When we insert a document without having set up docvalues */ public void testZeroDefault() throws Exception { insertTestDocuments(10, true); SolrQuery query = new SolrQuery("*:*"); String dvFieldFunction = String.format("field(%s)", WEIGHT_DV); query.set("fl", dvFieldFunction); QueryResponse resp = solr.query(query); SolrDocumentList docs = resp.getResults(); assertEquals(0, docs.get(0).getFirstValue(dvFieldFunction)); }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
private void assertDocValues(int n) throws SolrServerException { SolrQuery query = new SolrQuery("*:*"); query.setSort(WEIGHT_DV, ORDER.desc); assertEquals(uri(1), getFirstUri(query)); query.setSort(WEIGHT_DV, ORDER.asc); assertEquals(uri(n), getFirstUri(query)); }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
private void assertDocValue(String uri, Integer dv) throws SolrServerException { final SolrQuery query = new SolrQuery(String.format("%s:\"%s\"", URI, uri)); final String weightField = String.format("field(%s)", WEIGHT_DV); query.setFields(URI, weightField); QueryResponse resp = solr.query(query); SolrDocumentList docs = resp.getResults(); Integer wt = (Integer) docs.get(0).getFirstValue(weightField); assertEquals(dv, wt);/*from w ww . j a v a 2s.co m*/ }
From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java
License:Apache License
private void assertNoDocValues() throws SolrServerException { SolrQuery query = new SolrQuery("*:*"); String firstUri = getFirstUri(query); // with no doc values, should get the same doc first: query.setSort(WEIGHT_DV, ORDER.desc); assertEquals(firstUri, getFirstUri(query)); // no matter what the order is query.setSort(WEIGHT_DV, ORDER.asc); assertEquals(firstUri, getFirstUri(query)); }