/** * check if a given document, identified by url hash as document id exists * * @param id the url hash and document id * @return the load date if any entry in solr exists, -1 otherwise * @throws IOException */ @Override public LoadTimeURL getLoadTimeURL(String id) throws IOException { int responseCount = 0; DocListSearcher docListSearcher = null; try { docListSearcher = new DocListSearcher( "{!cache=false raw f=" + CollectionSchema.id.getSolrFieldName() + "}" + id, null, 0, 1, CollectionSchema.id.getSolrFieldName(), CollectionSchema.load_date_dt.getSolrFieldName()); responseCount = docListSearcher.response.size(); if (responseCount == 0) return null; SolrIndexSearcher searcher = docListSearcher.request.getSearcher(); DocIterator iterator = docListSearcher.response.iterator(); // for (int i = 0; i < responseCount; i++) { Document doc = searcher.doc(iterator.nextDoc(), AbstractSolrConnector.SOLR_ID_and_LOAD_DATE_FIELDS); if (doc == null) return null; return AbstractSolrConnector.getLoadTimeURL(doc); // } } catch (Throwable e) { ConcurrentLog.logException(e); throw new IOException(e.getMessage()); } finally { if (docListSearcher != null) docListSearcher.close(); } }
@Override public long getCountByQuery(String querystring) { int numFound = 0; DocListSearcher docListSearcher = null; try { docListSearcher = new DocListSearcher(querystring, null, 0, 0, CollectionSchema.id.getSolrFieldName()); numFound = docListSearcher.response.matches(); } finally { if (docListSearcher != null) docListSearcher.close(); } return numFound; }