Example usage for org.apache.lucene.analysis.miscellaneous PerFieldAnalyzerWrapper close

List of usage examples for org.apache.lucene.analysis.miscellaneous PerFieldAnalyzerWrapper close

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.miscellaneous PerFieldAnalyzerWrapper close.

Prototype

@Override
public void close() 

Source Link

Document

Frees persistent resources used by this Analyzer

Usage

From source file:nl.uva.DataHandler.Indexing.java

@Override
public void Indexer(String indexPathString) throws Exception, Throwable {
    try {/*w ww.jav a 2 s . com*/
        log.info(
                "----------------------- INDEXING - Override Version: for BM25 :)  --------------------------");

        Path ipath = FileSystems.getDefault().getPath(indexPathString);
        super.IndexesCleaner(indexPathString);
        MyAnalyzer myAnalyzer;
        if (!super.stopWordsRemoving)
            myAnalyzer = new MyAnalyzer(super.stemming);
        else
            myAnalyzer = new MyAnalyzer(super.stemming, super.LoadStopwords());

        Analyzer analyzer = myAnalyzer.getAnalyzer(configFile.getProperty("CORPUS_LANGUAGE"));
        PerFieldAnalyzerWrapper prfWrapper = new PerFieldAnalyzerWrapper(analyzer, super.analyzerMap);
        IndexWriterConfig irc = new IndexWriterConfig(prfWrapper);
        irc.setSimilarity(new BM25Similarity(1.2F, 0.75F));
        this.writer = new IndexWriter(new SimpleFSDirectory(ipath), irc);
        this.docIndexer();
        this.writer.commit();
        this.writer.close();
        analyzer.close();
        prfWrapper.close();
        log.info("-------------------------------------------------");
        log.info("Index is created successfully...");
        log.info("-------------------------------------------------");

    } catch (Exception ex) {
        log.error(ex);
        throw ex;
    }
}

From source file:nl.uva.lucenefacility.Indexer.java

public void Indexer(String indexPathString) throws Exception, Throwable {
    try {// ww w .ja v a  2s . c  o m
        log.info("----------------------- INDEXING--------------------------");

        Path ipath = FileSystems.getDefault().getPath(indexPathString);
        this.IndexesCleaner(indexPathString);

        if (!stopWordsRemoving || commonWordsRemoving) {
            //With Stopwords (or/ In order to make list of common words)

            MyAnalyzer myAnalyzer_noStoplist = new MyAnalyzer(stemming);
            Analyzer analyzer = myAnalyzer_noStoplist.getAnalyzer(configFile.getProperty("CORPUS_LANGUAGE"));
            PerFieldAnalyzerWrapper prfWrapper = new PerFieldAnalyzerWrapper(analyzer, analyzerMap);
            IndexWriterConfig irc = new IndexWriterConfig(prfWrapper);
            this.writer = new IndexWriter(new SimpleFSDirectory(ipath), irc);
            this.docIndexer();
            this.writer.commit();
            this.writer.close();
            analyzer.close();
            prfWrapper.close();
            log.info("-------------------------------------------------");
            log.info("Index without common words removing is created successfully...");
            log.info("-------------------------------------------------");
            if (commonWordsRemoving) {
                String tmpIndexPath = indexPathString + "/tmp";
                Path tmpipath = FileSystems.getDefault().getPath(tmpIndexPath);
                FileUtils.forceMkdir(new File(tmpIndexPath));
                IndexReader ireader = DirectoryReader.open(FSDirectory.open(ipath));
                IndexInfo iInfo = new IndexInfo(ireader);
                ArrayList<String> commonWs = iInfo.getTopTerms_TF("TEXT", this.commonWordNum);
                MyAnalyzer myAnalyzer_Stoplist = new MyAnalyzer(stemming, commonWs);
                Analyzer analyzer_2 = myAnalyzer_Stoplist
                        .getAnalyzer(configFile.getProperty("CORPUS_LANGUAGE"));
                PerFieldAnalyzerWrapper prfWrapper_2 = new PerFieldAnalyzerWrapper(analyzer_2, analyzerMap);
                IndexWriterConfig irc_2 = new IndexWriterConfig(prfWrapper_2);
                this.writer = new IndexWriter(new SimpleFSDirectory(tmpipath), irc_2);
                this.docIndexer();
                this.writer.commit();
                this.writer.close();
                analyzer_2.close();
                prfWrapper_2.close();
                FileUtils.deleteDirectory(new File(indexPathString));
                File index = new File(tmpIndexPath);
                File newIndex = new File(indexPathString);
                index.renameTo(newIndex);
                log.info("-------------------------------------------------");
                log.info("Index with common words removing is created successfully...");
                log.info("-------------------------------------------------");
            }
        } else if (stopWordsRemoving) {
            MyAnalyzer myAnalyzer_Stoplist = new MyAnalyzer(stemming, this.LoadStopwords());
            Analyzer analyzer = myAnalyzer_Stoplist.getAnalyzer(configFile.getProperty("CORPUS_LANGUAGE"));
            PerFieldAnalyzerWrapper prfWrapper = new PerFieldAnalyzerWrapper(analyzer, analyzerMap);
            IndexWriterConfig irc = new IndexWriterConfig(prfWrapper);
            this.writer = new IndexWriter(new SimpleFSDirectory(ipath), irc);
            this.docIndexer();
            this.writer.commit();
            this.writer.close();
            analyzer.close();
            prfWrapper.close();
            log.info("-------------------------------------------------");
            log.info("Index without common words removing is created successfully...");
            log.info("-------------------------------------------------");
        }

    } catch (Exception ex) {
        log.error(ex);
        throw ex;
    }
}