Package org.apache.solr.common

Examples of org.apache.solr.common.SolrDocument


    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(sortField);
      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(dedupField);

      final String uniqueKey = (String )solrDoc.getFirstValue("id");

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

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


        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++;
          return true;
View Full Code Here

                /**
                 * Loads the Solr documents in batches
                 * @return true if any document is loaded
                 */
                private boolean loadDocs() {
                    SolrDocument lastDocToRecord = null;

                    try {
                        if (log.isDebugEnabled()) {
                            log.debug("converting filter {}", filter);
                        }
View Full Code Here

    nl.add("response", list );
    list.setMaxScore(1.0f);
    list.setStart(10);
    list.setNumFound(12);

    SolrDocument doc = new SolrDocument();
    doc.addField( "f", fval );
    doc.addField( "b", bval );
    doc.addField( "s", sval );
    doc.addField( "f", 100 );
    list.add(doc);

    doc = new SolrDocument();
    doc.addField( "f", fval );
    doc.addField( "b", bval );
    doc.addField( "s", sval );
    doc.addField( "f", 101 );
    list.add(doc);

    nl.add("zzz",doc);

    new JavaBinCodec(null).marshal(nl,baos);
View Full Code Here

    // Set up a simple document
    NamedList r = new NamedList();
    List list =     new ArrayList();

    SolrDocument doc = new SolrDocument();
    doc.addField( "f", fval );
    doc.addField( "b", bval );
    doc.addField( "s", sval );
    doc.addField( "f", 100 );
    list.add(doc);

    doc = new SolrDocument();
    doc.addField( "f", fval );
    doc.addField( "b", bval );
    doc.addField( "s", sval );
    doc.addField( "f", 101 );
    list.add(doc);

    nl.add("zzz",list.iterator());

    new JavaBinCodec(null).marshal(nl,baos);
View Full Code Here

        NamedList sortFieldValues = (NamedList)(srsp.getSolrResponse().getResponse().get("sort_values"));

        // go through every doc in this response, construct a ShardDoc, and
        // put it in the priority queue so it can be ordered.
        for (int i=0; i<docs.size(); i++) {
          SolrDocument doc = docs.get(i);
          Object id = doc.getFieldValue(uniqueKeyField.getName());

          String prevShard = uniqueDoc.put(id, srsp.getShard());
          if (prevShard != null) {
            // duplicate detected
            numFound--;

            // For now, just always use the first encountered since we can't currently
            // remove the previous one added to the priority queue.  If we switched
            // to the Java5 PriorityQueue, this would be easier.
            continue;
            // make which duplicate is used deterministic based on shard
            // if (prevShard.compareTo(srsp.shard) >= 0) {
            //  TODO: remove previous from priority queue
            //  continue;
            // }
          }

          ShardDoc shardDoc = new ShardDoc();
          shardDoc.id = id;
          shardDoc.shard = srsp.getShard();
          shardDoc.orderInShard = i;
          Object scoreObj = doc.getFieldValue("score");
          if (scoreObj != null) {
            if (scoreObj instanceof String) {
              shardDoc.score = Float.parseFloat((String)scoreObj);
            } else {
              shardDoc.score = (Float)scoreObj;
View Full Code Here

    while (dit.hasNext()) {
      int docid = dit.nextDoc();

      Document luceneDoc = searcher.doc(docid, fields);
      SolrDocument doc = new SolrDocument();
      db.loadStoredFields(doc, luceneDoc);

      // this may be removed if XMLWriter gets patched to
      // include score from doc iterator in solrdoclist
      if (docs.hasScores()) {
        doc.addField("score", dit.score());
      } else {
        doc.addField("score", 0.0f);
      }

      list.add( doc );

      if( ids != null ) {
View Full Code Here

      if (o instanceof DocList) {
        writeDocList((DocList) o, codec);
        return null; // null means we completely handled it
      }
      if (o instanceof SolrDocument) {
        SolrDocument solrDocument = (SolrDocument) o;
        codec.writeSolrDocument(solrDocument, returnFields);
        return null;
      }
      if (o instanceof Document) {
        return getDoc((Document) o);
View Full Code Here

      DocIterator iterator = ids.iterator();
      for (int i = 0; i < sz; i++) {
        int id = iterator.nextDoc();
        Document doc = searcher.doc(id, returnFields);

        SolrDocument sdoc = getDoc(doc);

        if (includeScore && ids.hasScores()) {
          sdoc.addField("score", iterator.score());
        }

        codec.writeSolrDocument(sdoc);
      }
    }
View Full Code Here

      }
    }


    public SolrDocument getDoc(Document doc) {
      SolrDocument solrDoc = new SolrDocument();
      for (Fieldable f : (List<Fieldable>) doc.getFields()) {
        String fieldName = f.name();
        if (returnFields != null && !returnFields.contains(fieldName)) continue;
        FieldType ft = schema.getFieldTypeNoEx(fieldName);
        Object val;
        if (ft == null) {  // handle fields not in the schema
          if (f.isBinary()) val = f.binaryValue();
          else val = f.stringValue();
        } else {
          try {
            if (useFieldObjects && KNOWN_TYPES.contains(ft.getClass())) {
              val = ft.toObject(f);
            } else {
              val = ft.toExternal(f);
            }
          } catch (Exception e) {
            // There is a chance of the underlying field not really matching the
            // actual field type . So ,it can throw exception
            LOG.warn("Error reading a field from document : " + solrDoc, e);
            //if it happens log it and continue
            continue;
          }
        }
        solrDoc.addField(fieldName, val);
      }
      return solrDoc;
    }
View Full Code Here

TOP

Related Classes of org.apache.solr.common.SolrDocument

Copyright © 2018 www.massapicom. 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.