Java 类org.apache.lucene.analysis.commongrams.CommonGramsFilterFactory 实例源码

项目:search    文件:SolrStopwordsCarrot2LexicalDataFactory.java   
/**
 * Obtains stop words for a field from the associated
 * {@link StopFilterFactory}, if any.
 */
private Collection<CharArraySet> getSolrStopWordsForField(String fieldName) {
  // No need to synchronize here, Carrot2 ensures that instances
  // of this class are not used by multiple threads at a time.
  if (!solrStopWords.containsKey(fieldName)) {
    final Analyzer fieldAnalyzer = core.getLatestSchema().getFieldType(fieldName)
        .getIndexAnalyzer();
    if (fieldAnalyzer instanceof TokenizerChain) {
      final TokenFilterFactory[] filterFactories = ((TokenizerChain) fieldAnalyzer)
          .getTokenFilterFactories();
      for (TokenFilterFactory factory : filterFactories) {
        if (factory instanceof StopFilterFactory) {
          // StopFilterFactory holds the stop words in a CharArraySet
          solrStopWords.put(fieldName,
              ((StopFilterFactory) factory).getStopWords());
        }

        if (factory instanceof CommonGramsFilterFactory) {
          solrStopWords.put(fieldName,
              ((CommonGramsFilterFactory) factory)
                  .getCommonWords());
        }
      }
    }
  }
  return solrStopWords.get(fieldName);
}
项目:NYBC    文件:SolrStopwordsCarrot2LexicalDataFactory.java   
/**
 * Obtains stop words for a field from the associated
 * {@link StopFilterFactory}, if any.
 */
private Collection<CharArraySet> getSolrStopWordsForField(String fieldName) {
  // No need to synchronize here, Carrot2 ensures that instances
  // of this class are not used by multiple threads at a time.
  if (!solrStopWords.containsKey(fieldName)) {
    final Analyzer fieldAnalyzer = schema.getFieldType(fieldName)
        .getAnalyzer();
    if (fieldAnalyzer instanceof TokenizerChain) {
      final TokenFilterFactory[] filterFactories = ((TokenizerChain) fieldAnalyzer)
          .getTokenFilterFactories();
      for (TokenFilterFactory factory : filterFactories) {
        if (factory instanceof StopFilterFactory) {
          // StopFilterFactory holds the stop words in a CharArraySet
          solrStopWords.put(fieldName,
              ((StopFilterFactory) factory).getStopWords());
        }

        if (factory instanceof CommonGramsFilterFactory) {
          solrStopWords.put(fieldName,
              ((CommonGramsFilterFactory) factory)
                  .getCommonWords());
        }
      }
    }
  }
  return solrStopWords.get(fieldName);
}
项目:read-open-source-code    文件:SolrStopwordsCarrot2LexicalDataFactory.java   
/**
 * Obtains stop words for a field from the associated
 * {@link StopFilterFactory}, if any.
 */
private Collection<CharArraySet> getSolrStopWordsForField(String fieldName) {
  // No need to synchronize here, Carrot2 ensures that instances
  // of this class are not used by multiple threads at a time.
  if (!solrStopWords.containsKey(fieldName)) {
    final Analyzer fieldAnalyzer = core.getLatestSchema().getFieldType(fieldName)
        .getAnalyzer();
    if (fieldAnalyzer instanceof TokenizerChain) {
      final TokenFilterFactory[] filterFactories = ((TokenizerChain) fieldAnalyzer)
          .getTokenFilterFactories();
      for (TokenFilterFactory factory : filterFactories) {
        if (factory instanceof StopFilterFactory) {
          // StopFilterFactory holds the stop words in a CharArraySet
          solrStopWords.put(fieldName,
              ((StopFilterFactory) factory).getStopWords());
        }

        if (factory instanceof CommonGramsFilterFactory) {
          solrStopWords.put(fieldName,
              ((CommonGramsFilterFactory) factory)
                  .getCommonWords());
        }
      }
    }
  }
  return solrStopWords.get(fieldName);
}