コード例 #1
0
 /**
  * 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();
   }
 }
コード例 #2
0
    public DocListSearcher(
        final String querystring,
        String sort,
        final int offset,
        final int count,
        final String... fields) {
      // construct query
      final SolrQuery params =
          AbstractSolrConnector.getSolrQuery(querystring, sort, offset, count, fields);

      // query the server
      this.request = EmbeddedSolrConnector.this.request(params);
      SolrQueryResponse rsp = query(request);
      NamedList<?> nl = rsp.getValues();
      ResultContext resultContext = (ResultContext) nl.get("response");
      if (resultContext == null)
        log.warn("DocListSearcher: no response for query '" + querystring + "'");
      this.response =
          resultContext == null
              ? new DocSlice(0, 0, new int[0], new float[0], 0, 0.0f)
              : resultContext.docs;
    }