Exemple #1
0
 /**
  * Returns SearchResultsSlim for a given SolrDocumentList. A "slimmer" results object without the
  * "items" wrapper element is created for better transform to json.
  *
  * @param doc solr document list to build results
  * @return the SearchResultsSlim object for this solr result
  * @see SearchResultsSlim
  */
 private SearchResultsSlim buildSlimResults(SolrDocumentList docs) {
   SearchResultsSlim results = new SearchResultsSlim();
   Pagination pagination = new Pagination();
   pagination.setNumFound(docs.getNumFound());
   pagination.setStart(docs.getStart());
   pagination.setRows(limit);
   // List<ModsType> modsTypes = new ArrayList<ModsType>();
   List<Item> items = new ArrayList<Item>();
   for (final SolrDocument doc : docs) {
     Item item = new Item();
     ModsType modsType = null;
     try {
       modsType = (new ItemDAO()).getModsType(doc);
     } catch (JAXBException je) {
       log.error(je.getMessage());
       je.printStackTrace();
     }
     item.setModsType(modsType);
     items.add(item);
   }
   results.setItems(items);
   results.setPagination(pagination);
   if (facet != null) results.setFacet(facet);
   return results;
 }
Exemple #2
0
 public void writeSolrDocumentList(SolrDocumentList docs) throws IOException {
   writeTag(SOLRDOCLST);
   List<Number> l = new ArrayList<>(3);
   l.add(docs.getNumFound());
   l.add(docs.getStart());
   l.add(docs.getMaxScore());
   writeArray(l);
   writeArray(docs);
 }
  @Override
  public void writeSolrDocumentList(
      String name, SolrDocumentList docs, Set<String> fields, Map otherFields) throws IOException {
    boolean includeScore = false;
    if (fields != null) {
      includeScore = fields.contains("score");
      if (fields.size() == 0 || (fields.size() == 1 && includeScore) || fields.contains("*")) {
        fields = null; // null means return all stored fields
      }
    }

    int sz = docs.size();

    writeMapOpener(includeScore ? 4 : 3);
    incLevel();
    writeKey("numFound", false);
    writeLong(null, docs.getNumFound());
    writeMapSeparator();
    writeKey("start", false);
    writeLong(null, docs.getStart());

    if (includeScore && docs.getMaxScore() != null) {
      writeMapSeparator();
      writeKey("maxScore", false);
      writeFloat(null, docs.getMaxScore());
    }
    writeMapSeparator();
    // indent();
    writeKey("docs", false);
    writeArrayOpener(sz);

    incLevel();
    boolean first = true;

    SolrIndexSearcher searcher = req.getSearcher();
    for (SolrDocument doc : docs) {

      if (first) {
        first = false;
      } else {
        writeArraySeparator();
      }
      indent();
      writeSolrDocument(null, doc, fields, otherFields);
    }
    decLevel();
    writeArrayCloser();

    if (otherFields != null) {
      writeMap(null, otherFields, true, false);
    }

    decLevel();
    indent();
    writeMapCloser();
  }