<commit_before>/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package dk.statsbiblioteket.summa.index.lucene;

import dk.statsbiblioteket.summa.common.Record;
import dk.statsbiblioteket.summa.common.configuration.Configuration;
import dk.statsbiblioteket.summa.common.configuration.storage.XStorage;
import dk.statsbiblioteket.summa.common.filter.Filter;
import dk.statsbiblioteket.summa.common.filter.Payload;
import dk.statsbiblioteket.summa.common.filter.object.ObjectFilter;
import dk.statsbiblioteket.summa.common.lucene.LuceneIndexUtils;
import dk.statsbiblioteket.summa.common.lucene.index.IndexUtils;
import dk.statsbiblioteket.summa.common.unittest.LuceneTestHelper;
import dk.statsbiblioteket.util.Files;
import dk.statsbiblioteket.util.Profiler;
import dk.statsbiblioteket.util.Streams;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.NIOFSDirectory;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

@SuppressWarnings({"DuplicateStringLiteralInspection"})
public class LuceneManipulatorTest extends TestCase implements ObjectFilter {
    private static Log log = LogFactory.getLog(LuceneManipulatorTest.class);

    LuceneManipulator manipulator = null;

    public LuceneManipulatorTest(String name) {
        super(name);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        if (location.exists()) {
            Files.delete(location);
        }
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        if(manipulator != null) {
            manipulator.close();
        }
        if (location.exists()) {
            Files.delete(location);
        }
    }

    public static Test suite() {
        return new TestSuite(LuceneManipulatorTest.class);
    }

    public File location =
            new File("test/tmp/", "tempindex");

    private LuceneManipulator openIndex(int buffer) throws IOException {
        Configuration conf = Configuration.newMemoryBased();
        conf.set(LuceneManipulator.CONF_BUFFER_SIZE_PAYLOADS, buffer);
        manipulator = new LuceneManipulator(conf);
        manipulator.open(location);
        return manipulator;
    }

    public void testSimpleIndex() throws Exception {
        manipulator = openIndex(2);
        String[] ids = new String[]{"foo", "bar", "zoo"};
        for (String id: ids) {
            manipulator.update(getPayload(id, false));
        }
        manipulator.close();
        logIndex();
        LuceneTestHelper.verifyContent(
                new File(location, LuceneIndexUtils.LUCENE_FOLDER), ids);
    }<commit_msg>changed a temp directory location to point inside the target maven directory<commit_after>/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package dk.statsbiblioteket.summa.index.lucene;

import dk.statsbiblioteket.summa.common.Record;
import dk.statsbiblioteket.summa.common.configuration.Configuration;
import dk.statsbiblioteket.summa.common.configuration.storage.XStorage;
import dk.statsbiblioteket.summa.common.filter.Filter;
import dk.statsbiblioteket.summa.common.filter.Payload;
import dk.statsbiblioteket.summa.common.filter.object.ObjectFilter;
import dk.statsbiblioteket.summa.common.lucene.LuceneIndexUtils;
import dk.statsbiblioteket.summa.common.lucene.index.IndexUtils;
import dk.statsbiblioteket.summa.common.unittest.LuceneTestHelper;
import dk.statsbiblioteket.util.Files;
import dk.statsbiblioteket.util.Profiler;
import dk.statsbiblioteket.util.Streams;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.NIOFSDirectory;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

@SuppressWarnings({"DuplicateStringLiteralInspection"})
public class LuceneManipulatorTest extends TestCase implements ObjectFilter {
    private static Log log = LogFactory.getLog(LuceneManipulatorTest.class);

    LuceneManipulator manipulator = null;

    public LuceneManipulatorTest(String name) {
        super(name);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        if (location.exists()) {
            Files.delete(location);
        }
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        if(manipulator != null) {
            manipulator.close();
        }
        if (location.exists()) {
            Files.delete(location);
        }
    }

    public static Test suite() {
        return new TestSuite(LuceneManipulatorTest.class);
    }

    public File location =
            new File("target/tmp/", "tempindex");

    private LuceneManipulator openIndex(int buffer) throws IOException {
        Configuration conf = Configuration.newMemoryBased();
        conf.set(LuceneManipulator.CONF_BUFFER_SIZE_PAYLOADS, buffer);
        manipulator = new LuceneManipulator(conf);
        manipulator.open(location);
        return manipulator;
    }

    public void testSimpleIndex() throws Exception {
        manipulator = openIndex(2);
        String[] ids = new String[]{"foo", "bar", "zoo"};
        for (String id: ids) {
            manipulator.update(getPayload(id, false));
        }
        manipulator.close();
        logIndex();
        LuceneTestHelper.verifyContent(
                new File(location, LuceneIndexUtils.LUCENE_FOLDER), ids);
    }
{'fraction_non_alphanumeric': 0.0955368601169257, 'fraction_numerical': 0.0014259232853272494, 'mean_word_length': 3.5783289817232378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2019730', 'n_tokens_mistral': 2087, 'n_tokens_neox': 2069, 'n_words': 471}