Package org.apache.solr.common

Examples of org.apache.solr.common.SolrDocument


   * @param d SolrInputDocument to convert
   * @return a SolrDocument with the same fields and values as the SolrInputDocument
   */
  public static SolrDocument toSolrDocument( SolrInputDocument d )
  {
    SolrDocument doc = new SolrDocument();
    for( SolrInputField field : d ) {
      doc.setField( field.getName(), field.getValue() );
    }
    return doc;
  }
View Full Code Here


    }
  }
  public void testSingleVal4Array(){
    DocumentObjectBinder binder = new DocumentObjectBinder();
    SolrDocumentList solDocList = new SolrDocumentList();
    SolrDocument d = new SolrDocument();
    solDocList.add(d);
    d.setField("cat","hello");
    List<Item> l = binder.getBeans(Item.class,solDocList);
    Assert.assertEquals("hello", l.get(0).categories[0]);

  }
View Full Code Here

      return null;
    }

    // unordered case
    for (int i=0; i<a.size(); i++) {
      SolrDocument doc = a.get(i);
      Object key = doc.getFirstValue("id");
      SolrDocument docb=null;
      if (key==null) {
        // no id field to correlate... must compare ordered
        docb = b.get(i);
      } else {
        for (int j=0; j<b.size(); j++) {
          docb = b.get(j);
          if (key.equals(docb.getFirstValue("id"))) break;
        }
      }
      // if (docb == null) return "[id="+key+"]";
      cmp = compare(doc, docb, 0, handle);
      if (cmp != null) return "[id="+key+"]" + cmp;
View Full Code Here

        if(__prefixMap != null || __namespaceMap != null){
            log.warn("LoadNamespaceConfig called while mapping maps are NOT NULL!");
        }
        __prefixMap = new HashMap<String,String>();
        __namespaceMap = new HashMap<String,String>();
        SolrDocument config = null;
        try {
            config = getSolrDocument(FieldMapper.URI);
        } catch (IOException e) {
            log.error("Unable to load PathField Config from Index. (may be OK for the first run!)");
        } catch (SolrServerException e) {
            log.error("Unable to load PathField Config from Index. (may be OK for the first run!)");
        }
        if (config == null) {
            log.info("No PathFieldMapping Configuration present. Start with an empty mapping");
        } else {
            for (String fieldName : config.getFieldNames()) {
                String[] configFieldElements = fieldName.split(Character.toString(SolrConst.PATH_SEPERATOR));
                if (SPECIAL_CONFIG_FIELD.equals(configFieldElements[0])) {
                    if (SPECIAL_CONFIG_FIELD.length() > 1) {
                        String prefix = configFieldElements[1];
                        Object value = config.getFirstValue(fieldName);
                        if (value != null) {
                            if (__namespaceMap.containsKey(value.toString())) {
                                log.error("found two prefixes (" + __namespaceMap.get(value.toString())
                                          + " and " + prefix + ") for Namespace " + value.toString()
                                          + " keep the first one");
View Full Code Here

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        return String.valueOf(doc.getFieldValue(configuration.getPathField()));
                    }

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

                };
            } else {
View Full Code Here

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        return String.valueOf(doc.getFieldValue(
                                configuration.getPathField()));
                    }

                    @Override
                    public PropertyValue getValue(String columnName) {
                        if (QueryImpl.JCR_SCORE.equals(columnName)) {
                            float score = 0f;
                            Object scoreObj = doc.get("score");
                            if (scoreObj != null) {
                                score = (Float) scoreObj;
                            }
                            return PropertyValues.newDouble((double) score);
                        }
                        Object o = doc.getFieldValue(columnName);
                        return o == null ? null : PropertyValues.newString(o.toString());
                    }

                };
            } else {
View Full Code Here

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        return String.valueOf(doc.getFieldValue(
                                configuration.getPathField()));
                    }

                    @Override
                    public PropertyValue getValue(String columnName) {
                        if (QueryImpl.JCR_SCORE.equals(columnName)) {
                            float score = 0f;
                            Object scoreObj = doc.get("score");
                            if (scoreObj != null) {
                                score = (Float) scoreObj;
                            }
                            return PropertyValues.newDouble((double) score);
                        }
                        Object o = doc.getFieldValue(columnName);
                        return o == null ? null : PropertyValues.newString(o.toString());
                    }

                };
            } else {
View Full Code Here

        ssafSearchImpl = (SSAFSearchImpl) ac.getBean( "ssafSolrSearchBean" );
    }

    public void testSSAFSearchImpl() throws SSAFSolrException
    {
        SolrDocument solrDocument = ssafSearchImpl.searchWithRecordUri(
            SOLR_URL, "http://some.org/?recordKeyData=id:mpd103" );

        log.info( "Pointer file path:"
                + solrDocument.getFieldValue( "pointer_filepath" ) );
        log.info( "Stash file path:"
                + solrDocument.getFieldValue( "stash_filepath" ) );

    }
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

    }
    if( !"doc".equals( parser.getLocalName().toLowerCase() ) ) {
      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

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.