<commit_before>package org.jenkinsci.plugins.lucene.search;

import hudson.model.AbstractBuild;
import hudson.model.Cause;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.apache.lucene.search.highlight.QueryTermScorer;
import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.jenkinsci.plugins.lucene.search.config.SearchBackendEngine;

import java.io.File;
import java.io.IOException;
import java.util.*;

public class LuceneSearchBackend implements SearchBackend {
    private static final int MAX_NUM_FRAGMENTS = 5;
    private static final String[] EMPTY_ARRAY = new String[0];

    private static final Field.Store NO = Field.Store.YES;
    private static final Field.Store YES = Field.Store.YES;

    private enum Index {
        CONSOLE("console"), PROJECT_NAME("projectname"), BUILD_NUMBER("buildnumber", true, true), ID("id", false, true), PROJECT_DISPLAY_NAME(
                "projectdisplayname"), RESULT("result"), DURATION("duration", false, true), START_TIME("starttime", false, true), BUILT_ON(
                "builton"), START_CAUSE("startcause");
        public final String fieldName;
        public final boolean defaultSearchable;
        public final boolean numeric;

        private Index(String fieldName) {
            this(fieldName, true, false);
        }

        private Index(String fieldName, boolean defaultSearchable, boolean numeric) {
            this.fieldName = fieldName;
            this.defaultSearchable = defaultSearchable;
            this.numeric = numeric;
        }

        private static Map<String, Index> index;
        public static Index getIndex(String fieldName) {
            if (index == null) {
                Map<String, Index>  indexReverseLookup = new HashMap<String, Index>();
                for (Index idx : Index.values()) {
                    indexReverseLookup.put(idx.fieldName, idx);
                }
                index = indexReverseLookup;
            }
            return index.get(fieldName);
        }
    }

    private static final Version LUCENE_VERSION = Version.LUCENE_4_9;
    private static final int MAX_HITS_PER_PAGE = 100;

    private final Directory index;
    private final StandardAnalyzer analyzer;
    private final IndexWriter dbWriter;

    private DirectoryReader reader;
    private final File indexPath;

    public LuceneSearchBackend(final File indexPath) throws IOException {
        this.indexPath = indexPath;
        analyzer = new StandardAnalyzer(LUCENE_VERSION);
        index = FSDirectory.open(indexPath);
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        dbWriter = new IndexWriter(index, config);
        updateReader();
    }

    public static LuceneSearchBackend create(final Map<String, Object> config) {
        try {<commit_msg>No changes<commit_after>package org.jenkinsci.plugins.lucene.search;

import hudson.model.AbstractBuild;
import hudson.model.Cause;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.apache.lucene.search.highlight.QueryTermScorer;
import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.jenkinsci.plugins.lucene.search.config.SearchBackendEngine;

import java.io.File;
import java.io.IOException;
import java.util.*;

public class LuceneSearchBackend implements SearchBackend {
    private static final int MAX_NUM_FRAGMENTS = 5;
    private static final String[] EMPTY_ARRAY = new String[0];

    private static final Field.Store NO = Field.Store.YES;
    private static final Field.Store YES = Field.Store.YES;

    private enum Index {
        CONSOLE("console"), PROJECT_NAME("projectname"), BUILD_NUMBER("buildnumber", true, true), ID("id", false, true), PROJECT_DISPLAY_NAME(
                "projectdisplayname"), RESULT("result"), DURATION("duration", false, true), START_TIME("starttime", false, true), BUILT_ON(
                "builton"), START_CAUSE("startcause");
        public final String fieldName;
        public final boolean defaultSearchable;
        public final boolean numeric;

        private Index(String fieldName) {
            this(fieldName, true, false);
        }

        private Index(String fieldName, boolean defaultSearchable, boolean numeric) {
            this.fieldName = fieldName;
            this.defaultSearchable = defaultSearchable;
            this.numeric = numeric;
        }

        private static Map<String, Index> index;

        public static Index getIndex(String fieldName) {
            if (index == null) {
                Map<String, Index> indexReverseLookup = new HashMap<String, Index>();
                for (Index idx : Index.values()) {
                    indexReverseLookup.put(idx.fieldName, idx);
                }
                index = indexReverseLookup;
            }
            return index.get(fieldName);
        }
    }

    private static final Version LUCENE_VERSION = Version.LUCENE_4_9;
    private static final int MAX_HITS_PER_PAGE = 100;

    private final Directory index;
    private final Analyzer analyzer;
    private final IndexWriter dbWriter;

    private DirectoryReader reader;
    private final File indexPath;

    public LuceneSearchBackend(final File indexPath) throws IOException {
        this.indexPath = indexPath;
        analyzer = new StandardAnalyzer(LUCENE_VERSION);
        index = FSDirectory.open(indexPath);
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        dbWriter = new IndexWriter(index, config);
        updateReader();
    }

    public static LuceneSearchBackend create(final Map<String, Object> config) {
        try {
{'fraction_non_alphanumeric': 0.09225904028598927, 'fraction_numerical': 0.0019249278152069298, 'mean_word_length': 3.501237623762376, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7489783', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1969, 'n_words': 457}