@Override
    protected Query newFuzzyQuery(String text, int fuzziness) {
      BooleanQuery.Builder bq = new BooleanQuery.Builder();
      bq.setDisableCoord(true);

      for (Map.Entry<String, Float> entry : weights.entrySet()) {
        String field = entry.getKey();
        FieldType type = schema.getFieldType(field);
        Query fuzzy;

        if (type instanceof TextField) {
          // If the field type is a TextField then use the multi term analyzer.
          Analyzer analyzer = ((TextField) type).getMultiTermAnalyzer();
          String term = TextField.analyzeMultiTerm(field, text, analyzer).utf8ToString();
          fuzzy = new FuzzyQuery(new Term(entry.getKey(), term), fuzziness);
        } else {
          // If the type is *not* a TextField don't do any analysis.
          fuzzy = new FuzzyQuery(new Term(entry.getKey(), text), fuzziness);
        }

        float boost = entry.getValue();
        if (boost != 1f) {
          fuzzy = new BoostQuery(fuzzy, boost);
        }
        bq.add(fuzzy, BooleanClause.Occur.SHOULD);
      }

      return simplify(bq.build());
    }
    @Override
    protected Query newPrefixQuery(String text) {
      BooleanQuery.Builder bq = new BooleanQuery.Builder();
      bq.setDisableCoord(true);

      for (Map.Entry<String, Float> entry : weights.entrySet()) {
        String field = entry.getKey();
        FieldType type = schema.getFieldType(field);
        Query prefix;

        if (type instanceof TextField) {
          // If the field type is a TextField then use the multi term analyzer.
          Analyzer analyzer = ((TextField) type).getMultiTermAnalyzer();
          String term = TextField.analyzeMultiTerm(field, text, analyzer).utf8ToString();
          SchemaField sf = schema.getField(field);
          prefix = sf.getType().getPrefixQuery(qParser, sf, term);
        } else {
          // If the type is *not* a TextField don't do any analysis.
          SchemaField sf = schema.getField(field);
          prefix = type.getPrefixQuery(qParser, sf, text);
        }

        float boost = entry.getValue();
        if (boost != 1f) {
          prefix = new BoostQuery(prefix, boost);
        }
        bq.add(prefix, BooleanClause.Occur.SHOULD);
      }

      return simplify(bq.build());
    }
예제 #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.apache.solr.schema.TextField#init(org.apache.solr.schema.IndexSchema,
   * java.util.Map)
   */
  @Override
  protected void init(IndexSchema schema, Map<String, String> args) {
    String compLevel = args.remove("compressionlevel");
    if (compLevel != null)
      try {
        compressionLevel = Integer.parseInt(compLevel);
      } catch (NumberFormatException nfe) {
        compressionLevel = Deflater.BEST_COMPRESSION;
      }
    if (compressionLevel < Deflater.BEST_SPEED) compressionLevel = Deflater.BEST_SPEED;
    if (compressionLevel > Deflater.BEST_COMPRESSION) compressionLevel = Deflater.BEST_COMPRESSION;

    String compThreshold = args.remove("compressThreshold");
    if (compThreshold == null) compThreshold = args.remove("compressionThreshold");
    if (compThreshold != null)
      try {
        compressionThreshold = Integer.parseInt(compThreshold);
      } catch (NumberFormatException nfe) {
        compressionThreshold = 0;
      }
    if (compressionThreshold < 0) compressionThreshold = 0;

    super.init(schema, args);
  }