use of org.apache.lucene.analysis.core.KeywordAnalyzer in project geode by apache.
the class LuceneIndexCreationProfileJUnitTest method getNullField1AnalyzerLuceneIndexCreationProfile.
private LuceneIndexCreationProfile getNullField1AnalyzerLuceneIndexCreationProfile() {
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", null);
fieldAnalyzers.put("field2", new KeywordAnalyzer());
return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] { "field1", "field2" }, getPerFieldAnalyzerWrapper(fieldAnalyzers), fieldAnalyzers);
}
use of org.apache.lucene.analysis.core.KeywordAnalyzer in project geode by apache.
the class LuceneIndexXmlParserJUnitTest method generateWithFields.
@Test
public void generateWithFields() throws SAXException {
AttributesImpl attrs = new AttributesImpl();
XmlGeneratorUtils.addAttribute(attrs, LuceneXmlConstants.NAME, "index");
this.parser.startElement(LuceneXmlConstants.NAMESPACE, LuceneXmlConstants.INDEX, null, attrs);
addField("field1");
addField("field2");
addField("field3", KeywordAnalyzer.class.getName());
this.parser.endElement(LuceneXmlConstants.NAMESPACE, LuceneXmlConstants.INDEX, null);
assertEquals(this.rc, this.stack.peek());
LuceneIndexCreation index = (LuceneIndexCreation) this.rc.getExtensionPoint().getExtensions().iterator().next();
assertEquals("index", index.getName());
assertArrayEquals(new String[] { "field1", "field2", "field3" }, index.getFieldNames());
// Assert analyzers
Map<String, Analyzer> fieldAnalyzers = index.getFieldAnalyzers();
assertEquals(1, fieldAnalyzers.size());
assertTrue(fieldAnalyzers.containsKey("field3"));
assertTrue(fieldAnalyzers.get("field3") instanceof KeywordAnalyzer);
}
use of org.apache.lucene.analysis.core.KeywordAnalyzer in project incubator-atlas by apache.
the class QueryFactory method create.
private QueryExpression create(Request request, ResourceDefinition resourceDefinition) throws InvalidQueryException {
String queryString;
if (request.getCardinality() == Request.Cardinality.INSTANCE) {
String idPropertyName = resourceDefinition.getIdPropertyName();
queryString = String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName));
} else {
queryString = request.getQueryString();
}
QueryExpression queryExpression;
if (queryString != null && !queryString.isEmpty()) {
QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer());
queryParser.setLowercaseExpandedTerms(false);
queryParser.setAllowLeadingWildcard(true);
Query query;
try {
query = queryParser.parse((String) escape(queryString));
} catch (ParseException e) {
throw new InvalidQueryException(e.getMessage());
}
LOG.info("LuceneQuery: {}", query);
queryExpression = create(query, resourceDefinition);
} else {
queryExpression = new AlwaysQueryExpression();
}
// add query properties to request so that they are returned
request.addAdditionalSelectProperties(queryExpression.getProperties());
return queryExpression;
}
use of org.apache.lucene.analysis.core.KeywordAnalyzer in project lucene-solr by apache.
the class FieldTypePluginLoader method constructMultiTermAnalyzer.
// The point here is that, if no multiterm analyzer was specified in the schema file, do one of several things:
// 1> If legacyMultiTerm == false, assemble a new analyzer composed of all of the charfilters,
// lowercase filters and asciifoldingfilter.
// 2> If legacyMultiTerm == true just construct the analyzer from a KeywordTokenizer. That should mimic current behavior.
// Do the same if they've specified that the old behavior is required (legacyMultiTerm="true")
private Analyzer constructMultiTermAnalyzer(Analyzer queryAnalyzer) {
if (queryAnalyzer == null)
return null;
if (!(queryAnalyzer instanceof TokenizerChain)) {
return new KeywordAnalyzer();
}
TokenizerChain tc = (TokenizerChain) queryAnalyzer;
MultiTermChainBuilder builder = new MultiTermChainBuilder();
CharFilterFactory[] charFactories = tc.getCharFilterFactories();
for (CharFilterFactory fact : charFactories) {
builder.add(fact);
}
builder.add(tc.getTokenizerFactory());
for (TokenFilterFactory fact : tc.getTokenFilterFactories()) {
builder.add(fact);
}
return builder.build();
}
Aggregations