List of usage examples for org.apache.solr.client.solrj SolrQuery size
public int size()
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.RankerCreationUtil.java
License:Open Source License
/** * Retrieve a {@link CandidateAnswer} with its {@code threadPostId} by querying the /select * endpoint with query THREAD_POST_ID:x//ww w. j a va 2s . c o m * * @param searcher An initialized {@link RetrieveAndRankSearcher} * @param threadPostId The THREAD_POST_ID of the answer thread * @return * @throws IOException * @throws IngestionException */ public static CandidateAnswer getCandidateAnswerById(RetrieveAndRankSearcher searcher, String threadPostId) throws IOException, IngestionException { CandidateAnswer answer = null; try { SolrQuery featureSolrQuery = new SolrQuery( RetrieveAndRankSearcherConstants.ID_FIELD + ":" + threadPostId); // specify the request handler for the feature query featureSolrQuery.setRequestHandler(RetrieveAndRankSearcherConstants.SELECT_REQUEST_HANDLER); // We expect only one response since THREAD_POST_ID is a unique key if (featureSolrQuery.size() != 1) { throw new IngestionException(threadPostId); } featureSolrQuery.setRows(1); final QueryRequest featureRequest = new QueryRequest(featureSolrQuery); QueryResponse featureResponse = null; featureResponse = searcher.processSolrRequest(featureRequest); for (SolrDocument doc : featureResponse.getResults()) { byte[] bin = (byte[]) doc.getFieldValue(IndexDocumentFieldName.SERIALIZED_THREAD.toString()); answer = StackExchangeThreadSerializer.deserializeThreadFromBinArr(bin); } } catch (IOException | SolrServerException | InterruptedException e) { logger.error(e.getMessage()); } return answer; }