Examples of SolrDocument


Examples of org.apache.solr.common.SolrDocument

    }
  }

  private static SolrDocument getDoc(int id, IdxInfo info) throws IOException {
    Document doc = info.searcher.doc(id);
    SolrDocument solrDoc = new SolrDocument();
    for (Fieldable f : doc.getFields()) {
      String fieldName = f.name();
      if (info.returnFields != null && !info.returnFields.contains(fieldName))
        continue;
      SchemaField sf = info.schema.getFieldOrNull(fieldName);
      FieldType ft = null;
      if (sf != null) ft = sf.getType();
      Object val = null;
      if (ft == null) { // handle fields not in the schema
        if (f.isBinary())
          val = f.getBinaryValue();
        else
          val = f.stringValue();
      } else {
        try {
          if (BinaryResponseWriter.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;
        }
      }
      if (sf != null && sf.multiValued() && !solrDoc.containsKey(fieldName)) {
        ArrayList l = new ArrayList();
        l.add(val);
        solrDoc.addField(fieldName, l);
      } else {
        solrDoc.addField(fieldName, val);
      }
    }

    return solrDoc;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

      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

Examples of org.apache.solr.common.SolrDocument

      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

Examples of org.apache.solr.common.SolrDocument

      }
    }


    public SolrDocument getDoc(Document doc) {
      SolrDocument solrDoc = new SolrDocument();
      for (Fieldable f : doc.getFields()) {
        String fieldName = f.name();
        if (returnFields != null && !returnFields.contains(fieldName)) continue;
        SchemaField sf = schema.getFieldOrNull(fieldName);
        FieldType ft = null;
        if(sf != null) ft =sf.getType();
        Object val;
        if (ft == null) {  // handle fields not in the schema
          if (f.isBinary()) val = f.getBinaryValue();
          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;
          }
        }
        if(sf != null && sf.multiValued() && !solrDoc.containsKey(fieldName)){
          ArrayList l = new ArrayList();
          l.add(val);
          solrDoc.addField(fieldName, l);
        } else {
          solrDoc.addField(fieldName, val);
        }
      }
      return solrDoc;
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    }
    if( !"doc".equals( parser.getLocalName().toLowerCase(Locale.ENGLISH) ) ) {
      throw new RuntimeException( "must be 'lst', not: "+parser.getLocalName() );
    }

    SolrDocument doc = new SolrDocument();
    StringBuilder builder = new StringBuilder();
    KnownType type = null;
    String name = null;
   
    // just eat up the events...
    int depth = 0;
    while( true )
    {
      switch (parser.next()) {
      case XMLStreamConstants.START_ELEMENT:
        depth++;
        builder.setLength( 0 ); // reset the text
        type = KnownType.get( parser.getLocalName() );
        if( type == null ) {
          throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() );
        }
       
        name = null;
        int cnt = parser.getAttributeCount();
        for( int i=0; i<cnt; i++ ) {
          if( "name".equals( parser.getAttributeLocalName( i ) ) ) {
            name = parser.getAttributeValue( i );
            break;
          }
        }
       
        if( name == null ) {
          throw new XMLStreamException( "requires 'name' attribute: "+parser.getLocalName(), parser.getLocation() );
        }
       
        // Handle multi-valued fields
        if( type == KnownType.ARR ) {
          for( Object val : readArray( parser ) ) {
            doc.addField( name, val );
          }
          depth--; // the array reading clears out the 'endElement'
        }
        else if( !type.isLeaf ) {
          throw new XMLStreamException( "must be value or array", parser.getLocation() );
        }
        break;
       
      case XMLStreamConstants.END_ELEMENT:
        if( --depth < 0 ) {
          return doc;
        }
        //System.out.println( "FIELD:"+type+"::"+name+"::"+builder );
        Object val = type.read( builder.toString().trim() );
        if( val == null ) {
          throw new XMLStreamException( "error reading value:"+type, parser.getLocation() );
        }
        doc.addField( name, val );
        break;

      case XMLStreamConstants.SPACE: // TODO?  should this be trimmed? make sure it only gets one/two space?
      case XMLStreamConstants.CDATA:
      case XMLStreamConstants.CHARACTERS:
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

  public String match(String title, int year, Set<String> cast) throws SolrServerException {
    Iterator<SolrDocument> di = getCandidates(title);
    Match bestMatch = null;
    Match secMatch = null;
    while (di.hasNext()) { //<co id="co.rm.docs"/>
      SolrDocument doc = di.next();
      String id = (String) doc.getFieldValue("imdb");
      String ititle = (String) doc.getFieldValue("title");
      Integer iyear = (Integer) doc.getFieldValue("year");
      Set<String> icast = constructCastSet(doc.getFieldValues("cast"));
      float score = score(title,year,cast,ititle,iyear,icast); //<co id="co.rm.score"/>
      if (bestMatch == null || score > bestMatch.score) { //<co id="co.rm.best"/>
        secMatch = bestMatch;
        bestMatch = new Match(score,id,title,year,cast);
      }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    SolrDocumentList dl = response.getResults();
    Iterator<SolrDocument> di = dl.iterator();
    float maxDistance = 0;
    String suggestion = null;
    while (di.hasNext()) {
      SolrDocument doc = di.next();
      String word = (String) doc.getFieldValue("word");
      float distance = sd.getDistance(word, spelling); //<co id="co.dym.edit"/>
      if (distance > maxDistance) {
        maxDistance = distance;
        suggestion = word; //<co id="co.dym.max"/>
      }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    final QueryResponse response = this.getServer().query(query);
    final SolrDocumentList docList = response.getResults();

    final int size = docList.size();
    final String docIDs[] = new String[size];
    SolrDocument doc = null;
    for (int i = 0; i < size; i++) {
      doc = docList.get(i);
      docIDs[i] = (String) doc.getFieldValue(retrievedField);
    }
    return docIDs;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        String path = String.valueOf(doc.getFieldValue(
                                configuration.getPathField()));
                        if ("/".equals(path)) {
                            return "/";
                        } else {
                            return path.substring(0, path.length() - 1);
                        }
                    }

                    @Override
                    public PropertyValue getValue(String columnName) {
                        Object o = doc.getFieldValue(columnName);
                        return o == null ? null : PropertyValues.newString(o.toString());
                    }

                };
            } else {
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

        QueryResponse response = executeSolrQuery("id:MA147LL/A");

        assertEquals(0, response.getStatus());
        assertEquals(1, response.getResults().getNumFound());

        SolrDocument doc = response.getResults().get(0);
        assertEquals("Apple 60 GB iPod with Video Playback Black", doc.getFieldValue("name"));
        assertEquals("Apple Computer Inc.", doc.getFieldValue("manu"));
    }
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.