Package org.apache.solr.core

Examples of org.apache.solr.core.SolrException


        String type = DOMUtil.getAttr(attrs,"type","field " + name);
        String val;

        FieldType ft = fieldTypes.get(type);
        if (ft==null) {
          throw new SolrException(400,"Unknown fieldtype '" + type + "'",false);
        }

        Map<String,String> args = DOMUtil.toMapExcept(attrs, "name", "type");

        SchemaField f = SchemaField.create(name,ft,args);

        if (node.getNodeName().equals("field")) {
          fields.put(f.getName(),f);
          log.fine("field defined: " + f);
        } else if (node.getNodeName().equals("dynamicField")) {
          dFields.add(new DynamicField(f));
          log.fine("dynamic field defined: " + f);
        } else {
          // we should never get here
          throw new RuntimeException("Unknown field type");
        }
      }

    // OK, now sort the dynamic fields largest to smallest size so we don't get
    // any false matches.  We want to act like a compiler tool and try and match
    // the largest string possible.
    Collections.sort(dFields);

    log.finest("Dynamic Field Ordering:" + dFields);

    // stuff it in a normal array for faster access
    dynamicFields = (DynamicField[])dFields.toArray(new DynamicField[dFields.size()]);


    Node node = (Node) xpath.evaluate("/schema/similarity/@class", document, XPathConstants.NODE);
    if (node==null) {
      similarity = new DefaultSimilarity();
      log.fine("using default similarity");
    } else {
      similarity = (Similarity)Config.newInstance(node.getNodeValue().trim());
      log.fine("using similarity " + similarity.getClass().getName());
    }

    node = (Node) xpath.evaluate("/schema/defaultSearchField/text()", document, XPathConstants.NODE);
    if (node==null) {
      log.warning("no default search field specified in schema.");
    } else {
      defaultSearchFieldName=node.getNodeValue().trim();
      // throw exception if specified, but not found or not indexed
      if (defaultSearchFieldName!=null) getIndexedField(defaultSearchFieldName);
      log.info("default search field is "+defaultSearchFieldName);
    }

    node = (Node) xpath.evaluate("/schema/solrQueryParser/@defaultOperator", document, XPathConstants.NODE);
    if (node==null) {
      log.fine("using default query parser operator (OR)");
    } else {
      queryParserDefaultOperator=node.getNodeValue().trim();
      log.info("query parser default operator is "+queryParserDefaultOperator);
    }

    node = (Node) xpath.evaluate("/schema/uniqueKey/text()", document, XPathConstants.NODE);
    if (node==null) {
      log.warning("no uniqueKey specified in schema.");
    } else {
      uniqueKeyField=getIndexedField(node.getNodeValue().trim());
      uniqueKeyFieldName=uniqueKeyField.getName();
      uniqueKeyFieldType=uniqueKeyField.getType();
      log.info("unique key field: "+uniqueKeyFieldName);
    }

    /////////////// parse out copyField commands ///////////////
    // Map<String,ArrayList<SchemaField>> cfields = new HashMap<String,ArrayList<SchemaField>>();
    // expression = "/schema/copyField";

    ArrayList<DynamicCopy> dCopies = new ArrayList<DynamicCopy>();

    expression = "//copyField";
    nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);

      for (int i=0; i<nodes.getLength(); i++) {
        node = nodes.item(i);
        NamedNodeMap attrs = node.getAttributes();

        String source = DOMUtil.getAttr(attrs,"source","copyField definition");

        boolean sourceIsPattern = isWildCard(source);

        String dest = DOMUtil.getAttr(attrs,"dest","copyField definition");
        log.fine("copyField source='"+source+"' dest='"+dest+"'");
        SchemaField d = getField(dest);

        if(sourceIsPattern) {
          dCopies.add(new DynamicCopy(source, d));
        } else {
          // retrieve the field to force an exception if it doesn't exist
          SchemaField f = getField(source);

          SchemaField[] destArr = copyFields.get(source);
          if (destArr==null) {
            destArr=new SchemaField[]{d};
          } else {
            destArr = (SchemaField[])append(destArr,d);
          }
          copyFields.put(source,destArr);
        }
     }

      log.finest("Dynamic Copied Fields:" + dCopies);

      // stuff it in a normal array for faster access
      dynamicCopyFields = (DynamicCopy[])dCopies.toArray(new DynamicCopy[dCopies.size()]);

    } catch (SolrException e) {
      throw e;
    } catch(Exception e) {
      // unexpected exception...
      throw new SolrException(1,"Schema Parsing Failed",e,false);
    }

     analyzer = new SolrIndexAnalyzer();
     queryAnalyzer = new SolrQueryAnalyzer();
  }
View Full Code Here


    XPath xpath = XPathFactory.newInstance().newXPath();
    Node tokNode = (Node)xpath.evaluate("./tokenizer", node, XPathConstants.NODE);
    NodeList nList = (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET);

    if (tokNode==null){
      throw new SolrException(1,"analyzer without class or tokenizer & filter list");
    }
    TokenizerFactory tfac = readTokenizerFactory(tokNode);

    /******
    // oops, getChildNodes() includes text (newlines, etc) in addition
View Full Code Here

    // Hmmm, default field could also be implemented with a dynamic field of "*".
    // It would have to be special-cased and only used if nothing else matched.
    /***  REMOVED -YCS
    if (defaultFieldType != null) return new SchemaField(fieldName,defaultFieldType);
    ***/
    throw new SolrException(1,"undefined field "+fieldName);
  }
View Full Code Here

   */
  public FieldType getDynamicFieldType(String fieldName) {
     for (DynamicField df : dynamicFields) {
      if (df.matches(fieldName)) return df.prototype.getType();
    }
    throw new SolrException(400,"undefined field "+fieldName);
  }
View Full Code Here

    // TODO: test if lucene will accept an escaped ';', otherwise
    // we need to un-escape them before we pass to QueryParser
    try {
      String sreq = req.getQueryString();
      if (sreq==null) throw new SolrException(400,"Missing queryString");
      List<String> commands = StrUtils.splitSmart(sreq,';');

      String qs = commands.size() >= 1 ? commands.get(0) : "";
      Query query = QueryParsing.parseQuery(qs, req.getSchema());
View Full Code Here

      int flags = 0;
      if (fl != null) {
        flags |= U.setReturnFields(fl, rsp);
      }

      if (sreq==null) throw new SolrException(400,"Missing queryString");
      List<String> commands = StrUtils.splitSmart(sreq,';');

      String qs = commands.size() >= 1 ? commands.get(0) : "";
      Query query = QueryParsing.parseQuery(qs, defaultField, p, req.getSchema());
View Full Code Here

  public Field createField(SchemaField field, String externalVal, float boost) {
    String val;
    try {
      val = toInternal(externalVal);
    } catch (NumberFormatException e) {
      throw new SolrException(500, "Error while creating field '" + field + "' from value '" + externalVal + "'", e, false);
    }
    if (val==null) return null;

    Field f = new Field(field.getName(),
                        val,
View Full Code Here

      /* :TODO: let Locale/TimeZone come from init args for rounding only */
      DateMathParser p = new DateMathParser(UTC, Locale.US);
      try {
        return toInternal(p.parseMath(val.substring(3)));
      } catch (ParseException e) {
        throw new SolrException(400,"Invalid Date Math String:'" +val+'\'',e);
      }
    }
    throw new SolrException(400,"Invalid Date String:'" +val+'\'');
  }
View Full Code Here

    String sort = req.getParam("sort");
    if (null == sort || sort.equals("")) {
      return null;
    }

    SolrException sortE = null;
    QueryParsing.SortSpec ss = null;
    try {
      ss = QueryParsing.parseSort(sort, req.getSchema());
    } catch (SolrException e) {
      sortE = e;
View Full Code Here

      return query;

    } catch (ParseException e) {
      SolrCore.log(e);
      throw new SolrException(400,"Error parsing Lucene query",e);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.solr.core.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.