Search in sources :

Example 46 with Analyzer

use of org.apache.lucene.analysis.Analyzer in project geode by apache.

the class LuceneServiceImpl method createIndex.

public void createIndex(String indexName, String regionPath, Map<String, Analyzer> fieldAnalyzers) {
    if (fieldAnalyzers == null || fieldAnalyzers.isEmpty()) {
        throw new IllegalArgumentException("At least one field must be indexed");
    }
    Analyzer analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(), fieldAnalyzers);
    Set<String> fieldsSet = fieldAnalyzers.keySet();
    String[] fields = (String[]) fieldsSet.toArray(new String[fieldsSet.size()]);
    createIndex(indexName, regionPath, analyzer, fieldAnalyzers, fields);
}
Also used : StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PerFieldAnalyzerWrapper(org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper)

Example 47 with Analyzer

use of org.apache.lucene.analysis.Analyzer in project geode by apache.

the class LuceneIndexCreation method beforeCreate.

@Override
public void beforeCreate(Extensible<Region<?, ?>> source, Cache cache) {
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    Analyzer analyzer = this.fieldAnalyzers == null ? new StandardAnalyzer() : new PerFieldAnalyzerWrapper(new StandardAnalyzer(), this.fieldAnalyzers);
    try {
        service.createIndex(getName(), getRegionPath(), analyzer, this.fieldAnalyzers, getFieldNames());
    } catch (LuceneIndexExistsException e) {
        logger.info(LocalizedStrings.LuceneIndexCreation_IGNORING_DUPLICATE_INDEX_CREATION_0_ON_REGION_1.toLocalizedString(e.getIndexName(), e.getRegionPath()));
    }
}
Also used : LuceneIndexExistsException(org.apache.geode.cache.lucene.LuceneIndexExistsException) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PerFieldAnalyzerWrapper(org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper)

Example 48 with Analyzer

use of org.apache.lucene.analysis.Analyzer in project geode by apache.

the class LuceneIndexXmlGenerator method generate.

@Override
public void generate(CacheXmlGenerator cacheXmlGenerator) throws SAXException {
    final ContentHandler handler = cacheXmlGenerator.getContentHandler();
    handler.startPrefixMapping(PREFIX, NAMESPACE);
    AttributesImpl attr = new AttributesImpl();
    // TODO - should the type be xs:string ?
    XmlGeneratorUtils.addAttribute(attr, NAME, index.getName());
    XmlGeneratorUtils.startElement(handler, PREFIX, INDEX, attr);
    for (String field : index.getFieldNames()) {
        AttributesImpl fieldAttr = new AttributesImpl();
        XmlGeneratorUtils.addAttribute(fieldAttr, NAME, field);
        Analyzer analyzer = index.getFieldAnalyzers().get(field);
        if (analyzer != null) {
            XmlGeneratorUtils.addAttribute(fieldAttr, ANALYZER, analyzer.getClass().getName());
        }
        XmlGeneratorUtils.emptyElement(handler, PREFIX, FIELD, fieldAttr);
    }
    XmlGeneratorUtils.endElement(handler, PREFIX, INDEX);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Analyzer(org.apache.lucene.analysis.Analyzer) ContentHandler(org.xml.sax.ContentHandler)

Example 49 with Analyzer

use of org.apache.lucene.analysis.Analyzer in project geode by apache.

the class LuceneXmlParser method startField.

private void startField(Attributes atts) {
    // Ignore any whitespace noise between fields
    if (stack.peek() instanceof StringBuffer) {
        stack.pop();
    }
    if (!(stack.peek() instanceof LuceneIndexCreation)) {
        throw new CacheXmlException("lucene <field> elements must occur within lucene <index> elements");
    }
    LuceneIndexCreation creation = (LuceneIndexCreation) stack.peek();
    String name = atts.getValue(NAME);
    String className = atts.getValue(ANALYZER);
    if (className == null) {
        creation.addField(name);
    } else {
        Analyzer analyzer = createAnalyzer(className);
        creation.addFieldAndAnalyzer(name, analyzer);
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 50 with Analyzer

use of org.apache.lucene.analysis.Analyzer in project geode by apache.

the class LuceneXmlParser method createAnalyzer.

private Analyzer createAnalyzer(String className) {
    Object obj;
    try {
        Class c = InternalDataSerializer.getCachedClass(className);
        obj = c.newInstance();
    } catch (Exception ex) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(className), ex);
    }
    if (!(obj instanceof Analyzer)) {
        throw new CacheXmlException(LocalizedStrings.LuceneXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_ANALYZER.toLocalizedString(className));
    }
    return (Analyzer) obj;
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Analyzer(org.apache.lucene.analysis.Analyzer) SAXException(org.xml.sax.SAXException) CacheXmlException(org.apache.geode.cache.CacheXmlException)

Aggregations

Analyzer (org.apache.lucene.analysis.Analyzer)1020 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)396 Tokenizer (org.apache.lucene.analysis.Tokenizer)265 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)228 Document (org.apache.lucene.document.Document)207 Directory (org.apache.lucene.store.Directory)192 KeywordTokenizer (org.apache.lucene.analysis.core.KeywordTokenizer)176 BytesRef (org.apache.lucene.util.BytesRef)122 Test (org.junit.Test)119 TokenStream (org.apache.lucene.analysis.TokenStream)107 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)92 Term (org.apache.lucene.index.Term)92 IndexReader (org.apache.lucene.index.IndexReader)67 InputArrayIterator (org.apache.lucene.search.suggest.InputArrayIterator)65 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)64 Input (org.apache.lucene.search.suggest.Input)63 CharArraySet (org.apache.lucene.analysis.CharArraySet)58 ArrayList (java.util.ArrayList)57 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)57 TextField (org.apache.lucene.document.TextField)55