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

项目: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    文件:DocumentExpressionDictionaryFactory.java   
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
  if(params == null) {
    // should not happen; implies setParams was not called
    throw new IllegalStateException("Value of params not set");
  }

  String field = (String) params.get(FIELD);
  String payloadField = (String) params.get(PAYLOAD_FIELD);
  String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
  Set<SortField> sortFields = new HashSet<>();

  if (field == null) {
    throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
  }

  if (weightExpression == null) {
    throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
  }

  for(int i = 0; i < params.size(); i++) {
    if (params.getName(i).equals(SORT_FIELD)) {
      String sortFieldName = (String) params.getVal(i);

      SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);

      if (sortFieldType == null) {
        throw new IllegalArgumentException(sortFieldName + " could not be mapped to any appropriate type"
            + " [long, int, float, double]");
      }

      SortField sortField = new SortField(sortFieldName, sortFieldType);
      sortFields.add(sortField);
    }
  }

  return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
      sortFields), payloadField);
}
项目:read-open-source-code    文件:DocumentExpressionDictionaryFactory.java   
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
  if(params == null) {
    // should not happen; implies setParams was not called
    throw new IllegalStateException("Value of params not set");
  }

  String field = (String) params.get(FIELD);
  String payloadField = (String) params.get(PAYLOAD_FIELD);
  String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
  Set<SortField> sortFields = new HashSet<SortField>();

  if (field == null) {
    throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
  }

  if (weightExpression == null) {
    throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
  }

  for(int i = 0; i < params.size(); i++) {
    if (params.getName(i).equals(SORT_FIELD)) {
      String sortFieldName = (String) params.getVal(i);

      SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);

      if (sortFieldType == null) {
        throw new IllegalArgumentException(sortFieldName + " could not be mapped to any appropriate type"
            + " [long, int, float, double]");
      }

      SortField sortField = new SortField(sortFieldName, sortFieldType);
      sortFields.add(sortField);
    }
  }

  return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
      sortFields), payloadField);
}
项目:read-open-source-code    文件:DocumentExpressionDictionaryFactory.java   
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
  if(params == null) {
    // should not happen; implies setParams was not called
    throw new IllegalStateException("Value of params not set");
  }

  String field = (String) params.get(FIELD);
  String payloadField = (String) params.get(PAYLOAD_FIELD);
  String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
  Set<SortField> sortFields = new HashSet<>();

  if (field == null) {
    throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
  }

  if (weightExpression == null) {
    throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
  }

  for(int i = 0; i < params.size(); i++) {
    if (params.getName(i).equals(SORT_FIELD)) {
      String sortFieldName = (String) params.getVal(i);

      SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);

      if (sortFieldType == null) {
        throw new IllegalArgumentException(sortFieldName + " could not be mapped to any appropriate type"
            + " [long, int, float, double]");
      }

      SortField sortField = new SortField(sortFieldName, sortFieldType);
      sortFields.add(sortField);
    }
  }

  return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
      sortFields), payloadField);
}