Search in sources :

Example 1 with SearchScope

use of org.infinispan.search.mapper.scope.SearchScope in project infinispan by infinispan.

the class ProtobufValueWrapperIndexingTest method testIndexingWithWrapper.

public void testIndexingWithWrapper() {
    SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
    assertNotNull(searchMapping);
    // Store some test data:
    cache.put(new byte[] { 1, 2, 3 }, createUser("Adrian", "Nistor"));
    cache.put(new byte[] { 4, 5, 6 }, createUser("John", "Batman"));
    SearchSession session = searchMapping.getMappingSession();
    SearchScope<byte[]> scope = session.scope(byte[].class, "sample_bank_account.User");
    SearchQuery<Object> query = session.search(scope).select(f -> f.field("surname")).where(f -> f.match().field("name").matching("Adrian")).toQuery();
    List<Object> result = query.fetchAllHits();
    assertEquals(1, result.size());
    assertEquals("Nistor", result.get(0));
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) SearchScope(org.infinispan.search.mapper.scope.SearchScope) Address(org.infinispan.protostream.sampledomain.Address) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) SearchSession(org.infinispan.search.mapper.session.SearchSession) Assert.assertEquals(org.testng.Assert.assertEquals) TransactionMode(org.infinispan.transaction.TransactionMode) Test(org.testng.annotations.Test) User(org.infinispan.protostream.sampledomain.User) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) LOCAL_HEAP(org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP) ComponentRegistryUtils(org.infinispan.query.impl.ComponentRegistryUtils) Collections(java.util.Collections) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SearchSession(org.infinispan.search.mapper.session.SearchSession)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 LOCAL_HEAP (org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 Address (org.infinispan.protostream.sampledomain.Address)1 User (org.infinispan.protostream.sampledomain.User)1 ComponentRegistryUtils (org.infinispan.query.impl.ComponentRegistryUtils)1 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)1 SearchScope (org.infinispan.search.mapper.scope.SearchScope)1 SearchSession (org.infinispan.search.mapper.session.SearchSession)1 SingleCacheManagerTest (org.infinispan.test.SingleCacheManagerTest)1 TestCacheManagerFactory (org.infinispan.test.fwk.TestCacheManagerFactory)1 TransactionMode (org.infinispan.transaction.TransactionMode)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 AssertJUnit.assertNotNull (org.testng.AssertJUnit.assertNotNull)1 Test (org.testng.annotations.Test)1