Java Code Examples for org.apache.lucene.analysis.pattern.PatternReplaceFilterFactory

The following examples show how to use org.apache.lucene.analysis.pattern.PatternReplaceFilterFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: NestPathField.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setArgs(IndexSchema schema, Map<String, String> args) {
  args.putIfAbsent("stored", "false");
  args.putIfAbsent("omitTermFreqAndPositions", "true");
  args.putIfAbsent("omitNorms", "true");
  args.putIfAbsent("maxCharsForDocValues", "-1");
  super.setArgs(schema, args);

  // CustomAnalyzer is easy to use
  CustomAnalyzer customAnalyzer;
  try {
    customAnalyzer = CustomAnalyzer.builder(schema.getResourceLoader())
        .withDefaultMatchVersion(schema.getDefaultLuceneMatchVersion())
        .withTokenizer(KeywordTokenizerFactory.class)
        .addTokenFilter(PatternReplaceFilterFactory.class,
            "pattern", "#\\d*",
            "replace", "all")
        .build();
  } catch (IOException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);//impossible?
  }
  // Solr HTTP Schema APIs don't know about CustomAnalyzer so use TokenizerChain instead
  setIndexAnalyzer(new TokenizerChain(customAnalyzer));
  // leave queryAnalyzer as literal
}
 
Example 2
private void addTokenFilterForUnderscoreRemovalAroundToken(Builder builder) throws IOException {
    builder
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "^\\_", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\_$", "replacement", "", "replace", "all");
}
 
Example 3
private void addTokenFilterForTokenToDomainValue(Builder builder) throws IOException {
    builder
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\(", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\)$", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\)", "replacement", " ", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\{\\}", "replacement", "\\{ \\}", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\[\\]", "replacement", "\\[ \\]", "replace", "all");
}
 
Example 4
Source Project: airsonic   Source File: AnalyzerFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addTokenFilterForUnderscoreRemovalAroundToken(Builder builder) throws IOException {
    builder
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "^\\_", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\_$", "replacement", "", "replace", "all");
}
 
Example 5
Source Project: airsonic   Source File: AnalyzerFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addTokenFilterForTokenToDomainValue(Builder builder) throws IOException {
    builder
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\(", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\)$", "replacement", "", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\)", "replacement", " ", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\{\\}", "replacement", "\\{ \\}", "replace", "all")
        .addTokenFilter(PatternReplaceFilterFactory.class,
                "pattern", "\\[\\]", "replacement", "\\[ \\]", "replace", "all");
}