<commit_before>package com.github.rnewson.couchdb.lucene;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.lucene.index.IndexWriter;

import com.github.rnewson.couchdb.lucene.LuceneGateway.WriterCallback;

/**
 * Administrative functions.
 * 
 * <ul>
 * <li>_expunge
 * <li>_optimize
 * <li>_pause
 * <li>_resume
 * </ul>
 * 
 * @author rnewson
 * 
 */
public final class AdminServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    private final State state;

    AdminServlet(final State state) {
        this.state = state;
    }

    @Override
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final ViewSignature sig = state.locator.lookup(req);
        if (sig == null) {
            resp.sendError(400, "Invalid path.");
            return;
        }

        if ("/_expunge".equals(req.getPathInfo())) {
            state.lucene.withWriter(sig, new WriterCallback<Void>() {
                public Void callback(final IndexWriter writer) throws IOException {
                    writer.expungeDeletes(false);
                    return null;
                }
            });
            resp.setStatus(202);
            return;
        }

        if ("/_optimize".equals(req.getPathInfo())) {
            state.lucene.withWriter(sig, new WriterCallback<Void>() {
                public Void callback(final IndexWriter writer) throws IOException {
                    writer.optimize(false);
                    return null;
                }
            });
            resp.setStatus(202);
            return;
        }

        resp.sendError(400);
    }

}<commit_msg>fix admin servlet.<commit_after>package com.github.rnewson.couchdb.lucene;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.lucene.index.IndexWriter;

import com.github.rnewson.couchdb.lucene.LuceneGateway.WriterCallback;

/**
 * Administrative functions.
 * 
 * <ul>
 * <li>_expunge
 * <li>_optimize
 * <li>_pause
 * <li>_resume
 * </ul>
 * 
 * @author rnewson
 * 
 */
public final class AdminServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    private final State state;

    AdminServlet(final State state) {
        this.state = state;
    }

    @Override
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final ViewSignature sig = state.locator.lookup(req);
        if (sig == null) {
            resp.sendError(400, "Invalid path.");
            return;
        }

        final String command = req.getParameter("cmd");

        if ("expunge".equals(command)) {
            state.lucene.withWriter(sig, new WriterCallback<Void>() {
                public Void callback(final IndexWriter writer) throws IOException {
                    writer.expungeDeletes(false);
                    return null;
                }
            });
            resp.setStatus(202);
            return;
        }

        if ("optimize".equals(command)) {
            state.lucene.withWriter(sig, new WriterCallback<Void>() {
                public Void callback(final IndexWriter writer) throws IOException {
                    writer.optimize(false);
                    return null;
                }
            });
            resp.setStatus(202);
            return;
        }

        resp.sendError(400, "Bad request");
    }

}
{'fraction_non_alphanumeric': 0.10160992346265506, 'fraction_numerical': 0.006861968857218264, 'mean_word_length': 2.19831223628692, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107213', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1009, 'n_words': 218}