Indexer Service

contribute the service

                    
public static void contributeIndexerService(ClassFactory classFactory,
                                            MappedConfiguration<String, Resource> configuration)
{
    Resource cpResource = new ClasspathResource(classFactory.getClassLoader(), "lucene.properties");
    configuration.add(IndexerService.CONFIG_KEY_PROPERTIES, cpResource);
}

                

configure the service

content of sample lucene.properties

                    
# folder, where lucene should store its index files
search.index.folder = ./target/lucene

# true = create the index or overwrite the existing one
# false = append to the existing index
search.overwrite.index.folder = true

# set the yout favourity stop word analyzer
# if not set, org.apache.lucene.analysis.standard.StandardAnalyzer is used
search.analyzer.class.name = org.apache.lucene.analysis.de.GermanAnalyzer

# max legth for each search field.
search.max.field.length = 250000

# optimize the disk loacated index files, after ram index writer closed.
optimize.after.ramwriter.closed = false

# if true, enable the lucene log output
enable.lucene.log.output = true

                

using the service

                    
IndexerService service = registry.getService(IndexerService.class);
String[] fileNames = new String[]{"airbag.txt", "consp.txt", "aliens.txt"};

Document document = new Document();
document.add(new Field("id", "", Field.Store.YES, Field.Index.UN_TOKENIZED));
document.add(new Field("url", "", Field.Store.YES, Field.Index.UN_TOKENIZED));
document.add(new Field("content", "", Field.Store.YES, Field.Index.TOKENIZED));

for (String fileName : fileNames)
{
    Resource resource = new ClasspathResource(this.getClass().getClassLoader(), fileName);

    document.getField("id").setValue(fileName);
    document.getField("url").setValue(resource.toURL().toString());
    document.getField("content").setValue(readFile(resource.toURL()));
    service.addDocument(document);
}