Search in sources :

Example 1 with LuceneReindexArgs

use of net.jforum.search.LuceneReindexArgs in project jforum2 by rafaelsteil.

the class LuceneStatsAction method buildReindexArgs.

private LuceneReindexArgs buildReindexArgs() {
    Date fromDate = this.buildDateFromRequest("from");
    Date toDate = this.buildDateFromRequest("to");
    int firstPostId = 0;
    int lastPostId = 0;
    if (!StringUtils.isEmpty(this.request.getParameter("firstPostId"))) {
        firstPostId = this.request.getIntParameter("firstPostId");
    }
    if (!StringUtils.isEmpty(this.request.getParameter("lastPostId"))) {
        lastPostId = this.request.getIntParameter("lastPostId");
    }
    return new LuceneReindexArgs(fromDate, toDate, firstPostId, lastPostId, "yes".equals(this.request.getParameter("avoidDuplicatedRecords")), this.request.getIntParameter("type"));
}
Also used : LuceneReindexArgs(net.jforum.search.LuceneReindexArgs) Date(java.util.Date)

Example 2 with LuceneReindexArgs

use of net.jforum.search.LuceneReindexArgs in project jforum2 by rafaelsteil.

the class LuceneStatsAction method reconstructIndexFromScratch.

public void reconstructIndexFromScratch() {
    LuceneReindexArgs args = this.buildReindexArgs();
    boolean recreate = "recreate".equals(this.request.getParameter("indexOperationType"));
    LuceneReindexer reindexer = new LuceneReindexer(this.settings(), args, recreate);
    reindexer.startBackgroundProcess();
    this.list();
}
Also used : LuceneReindexArgs(net.jforum.search.LuceneReindexArgs) LuceneReindexer(net.jforum.search.LuceneReindexer)

Example 3 with LuceneReindexArgs

use of net.jforum.search.LuceneReindexArgs in project jforum2 by rafaelsteil.

the class LuceneCommandLineReindexer method parseCmdArgs.

private void parseCmdArgs(String[] args) {
    StringBuffer description = new StringBuffer(512);
    description.append("\n*** Going to reindex using the following options: \n");
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option recreateOption = parser.addBooleanOption("recreateIndex");
    CmdLineParser.Option typeOption = parser.addStringOption("type");
    CmdLineParser.Option pathOption = parser.addStringOption("path");
    CmdLineParser.Option firstPostIdOption = parser.addIntegerOption("firstPostId");
    CmdLineParser.Option lastPostIdOption = parser.addIntegerOption("lastPostId");
    CmdLineParser.Option fromDateOption = parser.addStringOption("fromDate");
    CmdLineParser.Option toDateOption = parser.addStringOption("toDate");
    CmdLineParser.Option avoidDuplicatedOption = parser.addBooleanOption("avoidDuplicatedRecords");
    try {
        parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
        System.out.println(e.getMessage());
        this.printUsage();
    }
    if (parser.getRemainingArgs().length > 0) {
        this.printUsage();
    }
    // Type
    String type = (String) parser.getOptionValue(typeOption);
    if (StringUtils.isEmpty(type) || (!type.equals("date") && !type.equals("message"))) {
        System.out.println("*** --type should be either date or message");
        this.printUsage();
    }
    description.append("\t-> Searching by ").append(type).append('\n');
    // Path
    this.path = (String) parser.getOptionValue(pathOption);
    if (StringUtils.isEmpty(this.path)) {
        System.out.println("*** --path is a required option. It should point to the root directory where JForum is installed");
        this.printUsage();
    }
    description.append("\t->App path: ").append(path).append('\n');
    // FirstPostId and LastPostId
    int firstPostId = ((Integer) parser.getOptionValue(firstPostIdOption, new Integer(0))).intValue();
    int lastPostId = ((Integer) parser.getOptionValue(lastPostIdOption, new Integer(0))).intValue();
    if ("message".equals(type)) {
        if (firstPostId == 0 || lastPostId == 0 || lastPostId <= firstPostId) {
            System.out.println("*** --firstPostId and --lastPostId are required fields when --type=message. " + "Also, --lastPostId should be greater than --firstPostId");
            this.printUsage();
        }
        description.append("\t-> From Post #").append(firstPostId).append(" to Post #").append(lastPostId).append('\n');
    }
    // FromDate and ToDate
    Date fromDate = null;
    Date toDate = null;
    if ("date".equals(type)) {
        fromDate = this.parseDate((String) parser.getOptionValue(fromDateOption));
        toDate = this.parseDate((String) parser.getOptionValue(toDateOption));
        if (fromDate == null || toDate == null) {
            System.out.println("*** --fromDate and --toDate are required fields when --type=date");
            this.printUsage();
        }
        description.append("\t-> From date ").append(fromDate).append(" to ").append(toDate).append('\n');
    }
    // Recreate
    this.recreate = ((Boolean) parser.getOptionValue(recreateOption, Boolean.FALSE)).booleanValue();
    description.append("\t->Recreate the index? ").append(this.recreate ? "Yes" : "No").append('\n');
    // AvoidDuplicatedRecords
    boolean avoidDuplicated = ((Boolean) parser.getOptionValue(avoidDuplicatedOption, Boolean.FALSE)).booleanValue();
    description.append("\t->Avoid duplicated records? ").append(avoidDuplicated ? "Yes" : "No").append('\n');
    this.reindexerArgs = new LuceneReindexArgs(fromDate, toDate, firstPostId, lastPostId, avoidDuplicated, "date".equals(type) ? LuceneReindexArgs.TYPE_DATE : LuceneReindexArgs.TYPE_MESSAGE);
    System.out.println(description);
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) LuceneReindexArgs(net.jforum.search.LuceneReindexArgs) Date(java.util.Date)

Aggregations

LuceneReindexArgs (net.jforum.search.LuceneReindexArgs)3 Date (java.util.Date)2 CmdLineParser (jargs.gnu.CmdLineParser)1 LuceneReindexer (net.jforum.search.LuceneReindexer)1