Search in sources :

Example 21 with KeywordAnalyzer

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);
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) HashMap(java.util.HashMap) Analyzer(org.apache.lucene.analysis.Analyzer) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer)

Example 22 with KeywordAnalyzer

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);
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Analyzer(org.apache.lucene.analysis.Analyzer) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 23 with 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;
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) RegexQuery(org.apache.lucene.sandbox.queries.regex.RegexQuery) ParseException(org.apache.lucene.queryparser.classic.ParseException) InvalidQueryException(org.apache.atlas.catalog.exception.InvalidQueryException)

Example 24 with KeywordAnalyzer

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();
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) TokenizerChain(org.apache.solr.analysis.TokenizerChain) CharFilterFactory(org.apache.lucene.analysis.util.CharFilterFactory) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory)

Aggregations

KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)24 Analyzer (org.apache.lucene.analysis.Analyzer)12 HashMap (java.util.HashMap)11 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)11 Document (org.apache.lucene.document.Document)5 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 StringField (org.apache.lucene.document.StringField)4 IndexWriter (org.apache.lucene.index.IndexWriter)4 ResultCollector (org.apache.geode.cache.execute.ResultCollector)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)3 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)3 Set (java.util.Set)2 LuceneService (org.apache.geode.cache.lucene.LuceneService)2