Package org.apache.solr.common

Examples of org.apache.solr.common.SolrException


      Fieldable[] fields = sfield.createFields(val, boost);
      if (fields.length > 0) {
        if (!sfield.multiValued()) {
          String oldValue = map.put(sfield.getName(), val);
          if (oldValue != null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "ERROR: multiple values encountered for non multiValued field " + sfield.getName()
                    + ": first='" + oldValue + "' second='" + val + "'");
          }
        }
        // Add each field
        for (Fieldable field : fields) {
          doc.add(field);
        }
      }
    } else {
      Fieldable field = sfield.createField(val, boost);
      if (field != null) {
        if (!sfield.multiValued()) {
          String oldValue = map.put(sfield.getName(), val);
          if (oldValue != null) {
            throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple values encountered for non multiValued field " + sfield.getName()
                    + ": first='" + oldValue + "' second='" + val + "'");
          }
        }
      }
      doc.add(field);
View Full Code Here


      }
    }

    // error if this field name doesn't match anything
    if (sfield==null && (copyFields==null || copyFields.size()==0)) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR:unknown field '" + name + "'");
    }
  }
View Full Code Here

      builder.append("missing required fields: " );
      for (String field : missingFields) {
        builder.append(field);
        builder.append(" ");
      }
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, builder.toString());
    }
   
    Document ret = doc; doc=null;
    return ret;
  }
View Full Code Here

      boolean used = false;
      float boost = field.getBoost();
     
      // Make sure it has the correct number
      if( sfield!=null && !sfield.multiValued() && field.getValueCount() > 1 ) {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
            "ERROR: "+getID(doc, schema)+"multiple values encountered for non multiValued field " +
              sfield.getName() + ": " +field.getValue() );
      }
     

      // load each field value
      boolean hasField = false;
      try {
        for( Object v : field ) {
          if( v == null ) {
            continue;
          }
          String val = null;
          hasField = true;
          boolean isBinaryField = false;
          if (sfield != null && sfield.getType() instanceof BinaryField) {
            isBinaryField = true;
            BinaryField binaryField = (BinaryField) sfield.getType();
            Fieldable f = binaryField.createField(sfield,v,boost);
            if(f != null){
              out.add(f);
            }
            used = true;
          } else {
            // TODO!!! HACK -- date conversion
            if (sfield != null && v instanceof Date && sfield.getType() instanceof DateField) {
              DateField df = (DateField) sfield.getType();
              val = df.toInternal((Date) v) + 'Z';
            } else if (v != null) {
              val = v.toString();
            }
 
            if (sfield != null) {
              used = true;
              addField(out, sfield, val, boost);
            }
          }
 
          // Check if we should copy this field to any other fields.
          // This could happen whether it is explicit or not.
          List<CopyField> copyFields = schema.getCopyFieldsList(name);
          for (CopyField cf : copyFields) {
            SchemaField destinationField = cf.getDestination();
            // check if the copy field is a multivalued or not
            if (!destinationField.multiValued() && out.get(destinationField.getName()) != null) {
              throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                      "ERROR: "+getID(doc, schema)+"multiple values encountered for non multiValued copy field " +
                              destinationField.getName() + ": " + val);
            }
 
            used = true;
            //Don't worry about poly fields here
            Fieldable [] fields = null;
            if (isBinaryField) {
              if (destinationField.getType() instanceof BinaryField) {
                BinaryField binaryField = (BinaryField) destinationField.getType();
                //TODO: safe to assume that binary fields only create one?
                fields = new Fieldable[]{binaryField.createField(destinationField, v, boost)};
              }
            } else {
              fields = destinationField.createFields(cf.getLimitedValue(val), boost);
            }
            if (fields != null) { // null fields are not added
              for (Fieldable f : fields) {
                out.add(f);
              }
            }
          }
         
          // In lucene, the boost for a given field is the product of the
          // document boost and *all* boosts on values of that field.
          // For multi-valued fields, we only want to set the boost on the
          // first field.
          boost = 1.0f;
        }
      }
      catch( Exception ex ) {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
            "ERROR: "+getID(doc, schema)+"Error adding field '" +
              field.getName() + "'='" +field.getValue()+"'", ex );
      }
     
      // make sure the field was used somehow...
      if( !used && hasField ) {
        throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
            "ERROR: "+getID(doc, schema)+"unknown field '" +name + "'");
      }
    }
   
       
View Full Code Here

    } else if ("none".equals(lockType)) {
      // Recipe for disaster
      log.error("CONFIGURATION WARNING: locks are disabled on " + path);     
      d.setLockFactory(NoLockFactory.getNoLockFactory());
    } else {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
              "Unrecognized lockType: " + rawLockType);
    }
    return d;
  }
View Full Code Here

        case XMLStreamConstants.START_ELEMENT:
          text.setLength(0);
          String localName = parser.getLocalName();
          if (!"field".equals(localName)) {
            log.warn("unexpected XML tag doc/" + localName);
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                    "unexpected XML tag doc/" + localName);
          }

          String attrVal = "";
          for (int i = 0; i < parser.getAttributeCount(); i++) {
View Full Code Here

    return got;
  }

  void assertEvent(int ev, int expected) {
    if( ev != expected ) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "Expected: "+JSONParser.getEventString( expected  )
          +" but got "+JSONParser.getEventString( ev )
          +" at ["+parser.getPosition()+"]" );
    }
  }
View Full Code Here

    Stack<Object> stack = new Stack<Object>();
    Object obj = null;
    boolean inArray = false;

    if( ev != JSONParser.OBJECT_START ) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "object should already be started" );
    }
   
    while( true ) {
      //System.out.println( ev + "["+JSONParser.getEventString(ev)+"] "+parser.wasKey() ); //+ parser.getString() );

      switch (ev) {
        case JSONParser.STRING:
          if( parser.wasKey() ) {
            obj = stack.peek();
            String v = parser.getString();
            if( obj instanceof SolrInputField ) {
              SolrInputField field = (SolrInputField)obj;
              if( "boost".equals( v ) ) {
                ev = parser.nextEvent();
                if( ev != JSONParser.NUMBER &&
                    ev != JSONParser.LONG && 
                    ev != JSONParser.BIGNUMBER ) {
                  throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "boost should have number! "+JSONParser.getEventString(ev) );
                }
                field.setBoost((float)parser.getDouble());
              }
              else if( "value".equals( ) ) {
                // nothing special...
                stack.push( field ); // so it can be popped
              }
              else {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "invalid key: "+v + " ["+ parser.getPosition()+"]" );
              }
            }
            else if( obj instanceof SolrInputDocument ) {
              SolrInputDocument doc = (SolrInputDocument)obj;
              SolrInputField f = doc.get( v );
              if( f == null ) {
                f = new SolrInputField( v );
                doc.put( f.getName(), f );
              }
              stack.push( f );
            }
            else {
              throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "hymmm ["+ parser.getPosition()+"]" );
            }
          }
          else {
            addValToField(stack, parser.getString(), inArray, parser);
          }
          break;

        case JSONParser.LONG:
        case JSONParser.NUMBER:
        case JSONParser.BIGNUMBER:
          addValToField(stack, parser.getNumberChars().toString(), inArray, parser);
          break;
         
        case JSONParser.BOOLEAN:
          addValToField(stack, parser.getBoolean(),inArray, parser);
          break;

        case JSONParser.NULL:
          parser.getNull();
          /*** if we wanted to remove the field from the document now...
          if (!inArray) {
            Object o = stack.peek();
            // if null was only value in the field, then remove the field
            if (o instanceof SolrInputField) {
              SolrInputField sif = (SolrInputField)o;
              if (sif.getValueCount() == 0) {
                sdoc.remove(sif.getName());
              }
            }
          }
          ***/

          addValToField(stack, null, inArray, parser);
          break;

        case JSONParser.OBJECT_START:
          if( stack.isEmpty() ) {
            stack.push( new SolrInputDocument() );
          }
          else {
            obj = stack.peek();
            if( obj instanceof SolrInputField ) {
              // should alreay be pushed...
            }
            else {
              throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "should not start new object with: "+obj + " ["+ parser.getPosition()+"]" );
            }
          }
          break;
        case JSONParser.OBJECT_END:
          obj = stack.pop();
          if( obj instanceof SolrInputDocument ) {
            return (SolrInputDocument)obj;
          }
          else if( obj instanceof SolrInputField ) {
            // should already be pushed...
          }
          else {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "should not start new object with: "+obj + " ["+ parser.getPosition()+"]" );
          }
          break;

        case JSONParser.ARRAY_START:
          inArray = true;
          break;
         
        case JSONParser.ARRAY_END:
          inArray = false;
          stack.pop(); // the val should have done it...
          break;
         
        default:
          System.out.println("UNKNOWN_EVENT_ID:"+ev);
          break;
      }

      ev = parser.nextEvent();
      if( ev == JSONParser.EOF ) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "should finish doc first!" );
      }
    }
  }
View Full Code Here

 
  static void addValToField( Stack stack, Object val, boolean inArray, JSONParser parser ) throws IOException
  {
    Object obj = stack.peek();
    if( !(obj instanceof SolrInputField) ) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "hymmm ["+parser.getPosition()+"]" );
    }

    SolrInputField f = inArray
      ? (SolrInputField)obj
      : (SolrInputField)stack.pop();
View Full Code Here

      String[] preTags, String[] postTags, BoundaryScanner bs );
 
  protected char getMultiValuedSeparatorChar( SolrParams params ){
    String separator = params.get( HighlightParams.MULTI_VALUED_SEPARATOR, " " );
    if( separator.length() > 1 ){
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
          HighlightParams.MULTI_VALUED_SEPARATOR + " parameter must be a char, but is \"" + separator + "\"" );
    }
    return separator.charAt( 0 );
  }
View Full Code Here

TOP

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

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.