<commit_before>package se.l4.silo.engine.index.search;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

import se.l4.silo.Entity;
import se.l4.silo.Transaction;
import se.l4.silo.engine.EntityCodec;
import se.l4.silo.engine.EntityDefinition;
import se.l4.silo.engine.LocalSilo;
import se.l4.silo.engine.internal.BasicTest;
import se.l4.silo.engine.internal.TestUserData;
import se.l4.silo.index.search.PaginatedSearchResult;
import se.l4.silo.index.search.SearchIndexQuery;

public class SearchObjectEntityTest
	extends BasicTest
{
	@Override
	protected LocalSilo.Builder setup(LocalSilo.Builder builder)
	{
		SearchIndexDefinition<TestUserData> index = SearchIndexDefinition.create("index", TestUserData.class)
			.addField(
				SearchFieldDefinition.create("name", TestUserData.class)
					.withType(SearchFields.TEXT)
					.withSupplier(TestUserData::getName)
					.build()
			)
			.addField(
				SearchFieldDefinition.create("age", TestUserData.class)
					.withType(SearchFields.INTEGER)
					.withSupplier(TestUserData::getAge)
					.build()
			)
			.addField(
				SearchFieldDefinition.create("active", TestUserData.class)
					.withType(SearchFields.BOOLEAN)
					.withSupplier(TestUserData::isActive)
					.build()
			)
			.build();

		return builder.addEntity(EntityDefinition.create("test", TestUserData.class)
			.withCodec(EntityCodec.serialized(serializers, TestUserData.class))
			.withId(Integer.class, TestUserData::getId)
			.addIndex(index)
			.build());
	}

	private Entity<Long, TestUserData> entity()
	{
		return instance().entity("test", Long.class, TestUserData.class);
	}

	@Test
	public void testStore()
	{
		Entity<Long, TestUserData> entity = entity();

		TestUserData data = new TestUserData(1, "Donna", 30, true);

		entity.store(data)
			.block();
	}

	@Test
	public void testQueryAll()
	{
		Entity<Long, TestUserData> entity = entity();

		TestUserData data = new TestUserData(1, "Donna", 30, true);

		entity.store(data)
			.block();

		PaginatedSearchResult<TestUserData> result = entity.fetch(
			SearchIndexQuery.create("index", TestUserData.class)
				.limited()
				.build()
		).block();

		assertThat(result.getSize(), is(1l));
	}

	@Test
	public void testQueryInTransaction()
	{
		Entity<Long, TestUserData> entity = entity();

		entity.store(new TestUserData(1, "Donna", 30, true))
			.block();

		Transaction tx = instance().newTransaction().block();

		entity.store(new TestUserData(2, "Steve", 30, true))
			.block();

		PaginatedSearchResult<TestUserData> result = tx.execute(v ->
			entity.fetch(
				SearchIndexQuery.create("index", TestUserData.class)
					.limited()
					.build()
			)
		).blockLast();

		assertThat(result.getSize(), is(1l));

		tx.commit();

		result = entity.fetch(
			SearchIndexQuery.create("index", TestUserData.class)
				.limited()
				.build()
		).block();

		assertThat(result.getSize(), is(2l));
	}
}<commit_msg>test(search-engine): Actually commit in SearchObjectEntityTest<commit_after>package se.l4.silo.engine.index.search;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

import se.l4.silo.Entity;
import se.l4.silo.Transaction;
import se.l4.silo.engine.EntityCodec;
import se.l4.silo.engine.EntityDefinition;
import se.l4.silo.engine.LocalSilo;
import se.l4.silo.engine.internal.BasicTest;
import se.l4.silo.engine.internal.TestUserData;
import se.l4.silo.index.search.PaginatedSearchResult;
import se.l4.silo.index.search.SearchIndexQuery;

public class SearchObjectEntityTest
	extends BasicTest
{
	@Override
	protected LocalSilo.Builder setup(LocalSilo.Builder builder)
	{
		SearchIndexDefinition<TestUserData> index = SearchIndexDefinition.create("index", TestUserData.class)
			.addField(
				SearchFieldDefinition.create("name", TestUserData.class)
					.withType(SearchFields.TEXT)
					.withSupplier(TestUserData::getName)
					.build()
			)
			.addField(
				SearchFieldDefinition.create("age", TestUserData.class)
					.withType(SearchFields.INTEGER)
					.withSupplier(TestUserData::getAge)
					.build()
			)
			.addField(
				SearchFieldDefinition.create("active", TestUserData.class)
					.withType(SearchFields.BOOLEAN)
					.withSupplier(TestUserData::isActive)
					.build()
			)
			.build();

		return builder.addEntity(EntityDefinition.create("test", TestUserData.class)
			.withCodec(EntityCodec.serialized(serializers, TestUserData.class))
			.withId(Integer.class, TestUserData::getId)
			.addIndex(index)
			.build());
	}

	private Entity<Long, TestUserData> entity()
	{
		return instance().entity("test", Long.class, TestUserData.class);
	}

	@Test
	public void testStore()
	{
		Entity<Long, TestUserData> entity = entity();

		TestUserData data = new TestUserData(1, "Donna", 30, true);

		entity.store(data)
			.block();
	}

	@Test
	public void testQueryAll()
	{
		Entity<Long, TestUserData> entity = entity();

		TestUserData data = new TestUserData(1, "Donna", 30, true);

		entity.store(data)
			.block();

		PaginatedSearchResult<TestUserData> result = entity.fetch(
			SearchIndexQuery.create("index", TestUserData.class)
				.limited()
				.build()
		).block();

		assertThat(result.getSize(), is(1l));
	}

	@Test
	public void testQueryInTransaction()
	{
		Entity<Long, TestUserData> entity = entity();

		entity.store(new TestUserData(1, "Donna", 30, true))
			.block();

		Transaction tx = instance().newTransaction().block();

		entity.store(new TestUserData(2, "Steve", 30, true))
			.block();

		PaginatedSearchResult<TestUserData> result = tx.execute(v ->
			entity.fetch(
				SearchIndexQuery.create("index", TestUserData.class)
					.limited()
					.build()
			)
		).blockLast();

		assertThat(result.getSize(), is(1l));

		tx.commit().block();

		result = entity.fetch(
			SearchIndexQuery.create("index", TestUserData.class)
				.limited()
				.build()
		).block();

		assertThat(result.getSize(), is(2l));
	}
}
{'fraction_non_alphanumeric': 0.14033627434659565, 'fraction_numerical': 0.0083236224404861, 'mean_word_length': 4.417493237150586, 'pattern_counts': {'":': 0, '<': 17, '<?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': '3407878', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2009, 'n_words': 336}