Java 类org.apache.lucene.search.suggest.analyzing.FuzzySuggester 实例源码

项目:preDict    文件:LuceneWordSearch.java   
@Override
public void indexingDone() {
    try {
        spellChecker = new DirectSpellChecker();
        spellChecker.setMaxEdits(2);
        spellChecker.setAccuracy(0.1f);
        spellChecker.setMinPrefix(0);
        reader = DirectoryReader.open(writer);

        fuzzySuggester = new FuzzySuggester(directory, "", writer.getAnalyzer());
        Dictionary dict = new DocumentValueSourceDictionary(reader, WORD_FIELD, new LongValuesSource() {

            @Override
            public boolean needsScores() {
                return false;
            }

            @Override
            public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
                return null;
            }
        });
        fuzzySuggester.build(dict);

        writer.close();
        searcher = new IndexSearcher(DirectoryReader.open(directory));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:search    文件:FuzzyLookupFactory.java   
@Override
public Lookup create(NamedList params, SolrCore core) {

  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();

  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;

  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;

  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }

  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;

  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString())
  : false;

  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;

  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;

  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;


  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;

  boolean unicodeAware = (params.get(UNICODE_AWARE) != null)
  ? Boolean.valueOf(params.get(UNICODE_AWARE).toString())
  : FuzzySuggester.DEFAULT_UNICODE_AWARE;

  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm,
      maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix,
      minFuzzyLength, unicodeAware);
}
项目:NYBC    文件:FuzzyLookupFactory.java   
@Override
public Lookup create(NamedList params, SolrCore core) {

  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getSchema().getFieldTypeByName(fieldTypeName.toString());
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();

  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;

  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;

  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }

  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;

  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;

  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;

  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;


  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;

  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, 
      maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions, maxEdits, 
      transpositions, nonFuzzyPrefix, minFuzzyLength);
}
项目:search-core    文件:FuzzyLookupFactory.java   
@Override
public Lookup create(NamedList params, SolrCore core) {

  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getSchema().getFieldTypeByName(fieldTypeName.toString());
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();

  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;

  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;

  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }

  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;

  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;

  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;

  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;


  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;

  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, 
      maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions, maxEdits, 
      transpositions, nonFuzzyPrefix, minFuzzyLength);
}
项目:read-open-source-code    文件:FuzzyLookupFactory.java   
@Override
public Lookup create(NamedList params, SolrCore core) {

  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();

  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;

  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;

  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }

  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;

  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString())
  : false;

  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;

  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;

  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;


  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;

  boolean unicodeAware = (params.get(UNICODE_AWARE) != null)
  ? Boolean.valueOf(params.get(UNICODE_AWARE).toString())
  : FuzzySuggester.DEFAULT_UNICODE_AWARE;

  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm,
      maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix,
      minFuzzyLength, unicodeAware);
}
项目:read-open-source-code    文件:FuzzyLookupFactory.java   
@Override
public Lookup create(NamedList params, SolrCore core) {

  // mandatory parameter
  Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
  if (fieldTypeName == null) {
    throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
  }
  // retrieve index and query analyzers for the field
  FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
  if (ft == null) {
    throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
  }
  Analyzer indexAnalyzer = ft.getIndexAnalyzer();
  Analyzer queryAnalyzer = ft.getQueryAnalyzer();

  // optional parameters
  boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
  : true;

  boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
  : true;

  int options = 0;
  if (exactMatchFirst) {
    options |= FuzzySuggester.EXACT_FIRST;
  }
  if (preserveSep) {
    options |= FuzzySuggester.PRESERVE_SEP;
  }

  int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
  : 256;

  int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
  ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
  : -1;

  boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null
  ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString())
  : false;

  int maxEdits = (params.get(MAX_EDITS) != null)
  ? Integer.parseInt(params.get(MAX_EDITS).toString())
  : FuzzySuggester.DEFAULT_MAX_EDITS;

  boolean transpositions = (params.get(TRANSPOSITIONS) != null)
  ? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
  : FuzzySuggester.DEFAULT_TRANSPOSITIONS;

  int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
  ? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
  :FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;


  int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
  ? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
  :FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;

  boolean unicodeAware = (params.get(UNICODE_AWARE) != null)
  ? Boolean.valueOf(params.get(UNICODE_AWARE).toString())
  : FuzzySuggester.DEFAULT_UNICODE_AWARE;

  return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm,
      maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix,
      minFuzzyLength, unicodeAware);
}