<commit_before>package org.apache.lucene.spatial.test;

import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class SpatialTestCase extends LuceneTestCase {

  private IndexReader indexReader;
  private IndexWriter indexWriter;
  private Directory directory;
  private IndexSearcher indexSearcher;

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    directory = newDirectory();

    IndexWriterConfig writerConfig = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT));
    indexWriter = new IndexWriter(directory, writerConfig);
  }

  @Override
  @After
  public void tearDown() throws Exception {
    if (indexWriter != null) {
      indexWriter.close();
    }
    if (indexSearcher != null) {
      indexSearcher.close();
    }
    if (indexReader != null) {
      indexReader.close();
    }
    if (directory != null) {
      directory.close();
    }
    super.tearDown();
  }

  // ================================================= Helper Methods ================================================

  protected void addDocument(Document doc) throws IOException {
    indexWriter.addDocument(doc);
  }

  protected void addDocumentsAndCommit(List<Document> documents) throws IOException {
    for (Document document : documents) {
      indexWriter.addDocument(document);
    }
    commit();
  }

  protected void deleteAllAndCommit() throws IOException {
    indexWriter.deleteAll();
    commit();
  }

  protected void commit() throws IOException {
    indexWriter.commit();
    if (indexReader == null) {
      indexReader = IndexReader.open(directory);
    } else {
      indexReader = indexReader.reopen();
    }
    indexSearcher = newSearcher(indexReader);
  }

  protected void verifyDocumentsIndexed(int numDocs) {
    assertEquals(numDocs, indexReader.numDocs());
  }
<commit_msg>made deleteAllAndCommit just deleteAll  (without commit)<commit_after>package org.apache.lucene.spatial.test;

import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class SpatialTestCase extends LuceneTestCase {

  private IndexReader indexReader;
  private IndexWriter indexWriter;
  private Directory directory;
  private IndexSearcher indexSearcher;

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    directory = newDirectory();

    IndexWriterConfig writerConfig = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT));
    indexWriter = new IndexWriter(directory, writerConfig);
  }

  @Override
  @After
  public void tearDown() throws Exception {
    if (indexWriter != null) {
      indexWriter.close();
    }
    if (indexSearcher != null) {
      indexSearcher.close();
    }
    if (indexReader != null) {
      indexReader.close();
    }
    if (directory != null) {
      directory.close();
    }
    super.tearDown();
  }

  // ================================================= Helper Methods ================================================

  protected void addDocument(Document doc) throws IOException {
    indexWriter.addDocument(doc);
  }

  protected void addDocumentsAndCommit(List<Document> documents) throws IOException {
    for (Document document : documents) {
      indexWriter.addDocument(document);
    }
    commit();
  }

  protected void deleteAll() throws IOException {
    indexWriter.deleteAll();
  }

  protected void commit() throws IOException {
    indexWriter.commit();
    if (indexReader == null) {
      indexReader = IndexReader.open(directory);
    } else {
      indexReader = indexReader.reopen();
    }
    indexSearcher = newSearcher(indexReader);
  }

  protected void verifyDocumentsIndexed(int numDocs) {
    assertEquals(numDocs, indexReader.numDocs());
  }

{'fraction_non_alphanumeric': 0.1364739183178326, 'fraction_numerical': 0.0, 'mean_word_length': 4.296573875802998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3112722', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1381, 'n_words': 296}