Examples of SolrDocument


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.springframework.data.solr.core.mapping.SolrDocument

   * @param type
   * @return empty string if {@link SolrDocument} not present or {@link SolrDocument#solrCoreName()} is blank.
   * @since 1.1
   */
  public static String resolveSolrCoreName(Class<?> type) {
    SolrDocument annotation = AnnotationUtils.findAnnotation(type, SolrDocument.class);
    if (annotation != null && StringUtils.isNotBlank(annotation.solrCoreName())) {
      return annotation.solrCoreName();
    }
    return "";
  }
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.