Java Code Examples for org.apache.lucene.analysis.core.KeywordTokenizerFactory

The following examples show how to use org.apache.lucene.analysis.core.KeywordTokenizerFactory. 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: ambari-logsearch   Source File: SolrUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String putWildCardByType(String str, String fieldType, String fieldTypeMetaData) {
  Map<String, Object> fieldTypeInfoMap = getFieldTypeInfoMap(fieldTypeMetaData);
  if (StringUtils.isNotBlank(fieldType)) {
    if (isSolrFieldNumber(fieldTypeInfoMap)) {
      String value = putEscapeCharacterForNumber(str, fieldTypeInfoMap);
      if (StringUtils.isNotBlank(value)) {
        return value;
      } else {
        return null;
      }
    } else if (checkTokenizer(StandardTokenizerFactory.class, fieldTypeInfoMap)) {
      return escapeForStandardTokenizer(str);
    } else if (checkTokenizer(KeywordTokenizerFactory.class, fieldTypeInfoMap) || "string".equalsIgnoreCase(fieldType)) {
      return makeSolrSearchStringWithoutAsterisk(str);
    } else if (checkTokenizer(PathHierarchyTokenizerFactory.class, fieldTypeInfoMap)) {
      return str;
    } else {
      return escapeQueryChars(str);
    }
  }
  return str;
}
 
Example 2
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 3
Source Project: lucene-solr   Source File: CustomAnalyzerStrField.java    License: Apache License 2.0 6 votes vote down vote up
public CustomAnalyzerStrField() {
  Random r = LuceneTestCase.random();

  // two arg constructor
  Analyzer a2 = new TokenizerChain
    (new KeywordTokenizerFactory(new HashMap<>()),
     r.nextBoolean() ? null : new TokenFilterFactory[0]);
  
  // three arg constructor
  Analyzer a3 = new TokenizerChain
    (r.nextBoolean() ? null : new CharFilterFactory[0],
     new KeywordTokenizerFactory(new HashMap<>()),
     r.nextBoolean() ? null : new TokenFilterFactory[0]);

  if (r.nextBoolean()) {
    indexAnalyzer = a2;
    queryAnalyzer = a3;
  } else {
    queryAnalyzer = a2;
    indexAnalyzer = a3;
  }
}
 
Example 4
private Builder createKeywordAnalyzerBuilder() throws IOException {
    return CustomAnalyzer.builder()
            .withTokenizer(KeywordTokenizerFactory.class);
}
 
Example 5
Source Project: airsonic   Source File: AnalyzerFactory.java    License: GNU General Public License v3.0 4 votes vote down vote up
private Builder createKeywordAnalyzerBuilder() throws IOException {
    return CustomAnalyzer.builder()
            .withTokenizer(KeywordTokenizerFactory.class);
}