Package fr.inra.lipm.jezlucene.action

Source Code of fr.inra.lipm.jezlucene.action.Remove

package fr.inra.lipm.jezlucene.action;

import java.io.IOException;

import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.NIOFSDirectory;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.inra.lipm.jezlucene.cfg.Configuration;

/**
* @author llegrand
*/
public class Remove extends Action {

    private static Logger logger = LoggerFactory.getLogger(Remove.class);

    @Option(required = true, name = "-q", aliases = { "--query" }, usage = "query")
    private String query;

    public void remove() throws IOException {
        final IndexWriter writer = new IndexWriter(new NIOFSDirectory(this.store), Configuration.WRITER_CFG);

        final QueryParser queryParser = new QueryParser(Configuration.VERSION, "", Configuration.ANALYZER);
        try {
            final Query validQuery = queryParser.parse(this.query);
            writer.deleteDocuments(validQuery);
        }
        catch (final ParseException e) {
            logger.error("Malformed lucene query: {}", e.getMessage());
            logger.trace("Stacktrace", e.fillInStackTrace());
        }
        finally {
            writer.close();
        }
    }
}
TOP

Related Classes of fr.inra.lipm.jezlucene.action.Remove

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.