Examples of SolrDocumentList


Examples of org.apache.solr.common.SolrDocumentList

        response = solr.query(solrQuery);
      } catch (final SolrServerException e) {
        throw new IOException(e);
      }

      final SolrDocumentList solrDocs = response.getResults();

      return new RecordReader<Text, SolrRecord>() {

        private int currentDoc = 0;

        public void close() throws IOException { }

        public Text createKey() {
          return new Text();
        }

        public SolrRecord createValue() {
          return new SolrRecord();
        }

        public long getPos() throws IOException {
          return currentDoc;
        }

        public float getProgress() throws IOException {
          return currentDoc / (float) numDocs;
        }

        public boolean next(Text key, SolrRecord value) throws IOException {
          if (currentDoc >= numDocs) {
            return false;
          }

          SolrDocument doc = solrDocs.get(currentDoc);
          String digest = (String) doc.getFieldValue(SolrConstants.DIGEST_FIELD);
          key.set(digest);
          value.readSolrDocument(doc);

          currentDoc++;
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

      response = solr.query(solrQuery);
    } catch (final SolrServerException e) {
      throw SolrWriter.makeIOException(e);
    }

    final SolrDocumentList docList = response.getResults();

    final Hit[] hitArr = new Hit[docList.size()];
    for (int i = 0; i < hitArr.length; i++) {
      final SolrDocument solrDoc = docList.get(i);

      final Object raw = solrDoc.getFirstValue(query.getParams().getSortField());
      WritableComparable sortValue;

      if (raw instanceof Integer) {
        sortValue = new IntWritable(((Integer)raw).intValue());
      } else if (raw instanceof Float) {
        sortValue = new FloatWritable(((Float)raw).floatValue());
      } else if (raw instanceof String) {
        sortValue = new Text((String)raw);
      } else if (raw instanceof Long) {
        sortValue = new LongWritable(((Long)raw).longValue());
      } else {
        throw new RuntimeException("Unknown sort value type!");
      }

      final String dedupValue = (String) solrDoc.getFirstValue(query.getParams().getDedupField());

      final String uniqueKey = (String )solrDoc.getFirstValue(searchUID);

      hitArr[i] = new Hit(uniqueKey, sortValue, dedupValue);
    }

    return new Hits(docList.getNumFound(), hitArr);
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    }
    return doc;
  }

  public SolrDocumentList readSolrDocumentList(FastInputStream dis) throws IOException {
    SolrDocumentList solrDocs = new SolrDocumentList();
    List list = (List) readVal(dis);
    solrDocs.setNumFound((Long) list.get(0));
    solrDocs.setStart((Long)list.get(1));
    solrDocs.setMaxScore((Float)list.get(2));

    List l = (List) readVal(dis);
    solrDocs.addAll(l);
    return solrDocs;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

   * @param request the ES RestRequest
   * @param response the ES SearchResponse
   * @return search results as a SolrDocumentList
   */
  private SolrDocumentList convertToSolrDocumentList(RestRequest request, SearchResponse response) {
    SolrDocumentList results = new SolrDocumentList();

    // get the ES hits
    SearchHits hits = response.getHits();

    // set the result information on the SolrDocumentList
    results.setMaxScore(hits.getMaxScore());
    results.setNumFound(hits.getTotalHits());
    results.setStart(request.paramAsInt("start", 0));

    // loop though the results and convert each
    // one to a SolrDocument
    for (SearchHit hit : hits.getHits()) {
      SolrDocument doc = new SolrDocument();

      // always add score to document
      doc.addField("score", hit.score());

      // attempt to get the returned fields
      // if none returned, use the source fields
      Map<String, SearchHitField> fields = hit.getFields();
      Map<String, Object> source = hit.sourceAsMap();
      if (fields.isEmpty()) {
        if (source != null) {
          for (String sourceField : source.keySet()) {
            Object fieldValue = source.get(sourceField);

            // ES does not return date fields as Date Objects
            // detect if the string is a date, and if so
            // convert it to a Date object
            if (fieldValue.getClass() == String.class) {
              if (datePattern.matcher(fieldValue.toString()).matches()) {
                fieldValue = dateFormat.parseDateTime(fieldValue.toString()).toDate();
              }
            }

            doc.addField(sourceField, fieldValue);
          }
        }
      } else {
        for (String fieldName : fields.keySet()) {
          SearchHitField field = fields.get(fieldName);
          Object fieldValue = field.getValue();

          // ES does not return date fields as Date Objects
          // detect if the string is a date, and if so
          // convert it to a Date object
          if (fieldValue.getClass() == String.class) {
            if (datePattern.matcher(fieldValue.toString()).matches()) {
              fieldValue = dateFormat.parseDateTime(fieldValue.toString()).toDate();
            }
          }

          doc.addField(fieldName, fieldValue);
        }
      }

      // add the SolrDocument to the SolrDocumentList
      results.add(doc);
    }

    return results;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

      if (docs instanceof DocSlice) {
        DocSlice doc_slice = (DocSlice) docs;
        results_found = doc_slice.matches();
        start = doc_slice.offset();
      } else {
        SolrDocumentList doc_list = (SolrDocumentList) docs;
        results_found = doc_list.getNumFound();
        start = doc_list.getStart();
      }
    }

    page_count = (int) Math.ceil(results_found / (double) results_per_page);
    current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0);
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    // adding one more document to test array indexes
    d = new SolrDocument();
    SolrDocument d2 = d;
    d.addField("id","2");

    SolrDocumentList sdl = new SolrDocumentList();
    sdl.add(d1);
    sdl.add(d2);
    rsp.add("response", sdl);
   
    w.write(buf, req, rsp);
    assertEquals("a:1:{s:8:\"response\";a:3:{s:8:\"numFound\";i:0;s:5:\"start\";i:0;s:4:\"docs\";a:2:{i:0;a:6:{s:2:\"id\";s:1:\"1\";s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;s:5:\"data4\";a:2:{s:7:\"data4.1\";s:7:\"hashmap\";s:7:\"data4.2\";s:5:\"hello\";}s:5:\"data5\";a:3:{i:0;s:7:\"data5.1\";i:1;s:7:\"data5.2\";i:2;s:7:\"data5.3\";}}i:1;a:1:{s:2:\"id\";s:1:\"2\";}}}}",
                 buf.toString());
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    d.addField("v_ss","there");
    d.addField("v2_ss","nice");
    d.addField("v2_ss","output");
    d.addField("score", "89.83");

    SolrDocumentList sdl = new SolrDocumentList();
    sdl.add(d1);
    sdl.add(d2);
   
    SolrQueryRequest req = req("q","*:*");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("response", sdl);
    QueryResponseWriter w = new CSVResponseWriter();
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    server.add(doc);

    server.commit();

    QueryResponse resp = server.query(new SolrQuery("*:*"));
    SolrDocumentList res = resp.getResults();
    List<Bean> beans = resp.getBeans(Bean.class);
    assertEquals(3, res.size());
    assertEquals(3, beans.size());
    for (SolrDocument d : res) {
      Integer id = (Integer) d.getFieldValue("id");
      byte[] data = (byte[]) d.getFieldValue("data");
      if (id == 1) {
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    if (useResults == true) {
      SearchClusteringEngine engine = getSearchClusteringEngine(rb);
      if (engine != null) {
        DocListAndSet results = rb.getResults();
        Map<SolrDocument,Integer> docIds = new HashMap<SolrDocument, Integer>(results.docList.size());
        SolrDocumentList solrDocList = engine.getSolrDocumentList(results.docList, rb.req, docIds);
        Object clusters = engine.cluster(rb.getQuery(), solrDocList, docIds, rb.req);
        rb.rsp.add("clusters", clusters);
      } else {
        log.warn("No engine for: " + name);
      }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

      return;
    }
    if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
      SearchClusteringEngine engine = getSearchClusteringEngine(rb);
      if (engine != null) {
        SolrDocumentList solrDocList = (SolrDocumentList)rb.rsp.getValues().get("response");
        // TODO: Currently, docIds is set to null in distributed environment.
        // This causes CarrotParams.PRODUCE_SUMMARY doesn't work.
        // To work CarrotParams.PRODUCE_SUMMARY under distributed mode, we can choose either one of:
        // (a) In each shard, ClusteringComponent produces summary and finishStage()
        //     merges these summaries.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.