org.hibernate.search.mapper.orm.Search Java Examples
The following examples show how to use
org.hibernate.search.mapper.orm.Search.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateSearchTestResource.java From quarkus with Apache License 2.0 | 6 votes |
@GET @Path("/search") @Produces(MediaType.TEXT_PLAIN) public String testSearch() { SearchSession searchSession = Search.session(entityManager); List<Person> person = searchSession.search(Person.class) .where(f -> f.match().field("name").matching("john")) .sort(f -> f.field("name_sort")) .fetchHits(20); assertEquals(2, person.size()); assertEquals("John Grisham", person.get(0).getName()); assertEquals("John Irving", person.get(1).getName()); person = searchSession.search(Person.class) .where(f -> f.nested().objectField("address").nest( f.match().field("address.city").matching("london"))) .sort(f -> f.field("name_sort")) .fetchHits(20); assertEquals(1, person.size()); assertEquals("David Lodge", person.get(0).getName()); return "OK"; }
Example #2
Source File: AdminEndpoint.java From hibernate-demos with Apache License 2.0 | 6 votes |
@POST @Path("/reindex") public Response reindex(@QueryParam("limit") Long limit, @QueryParam("idfetchsize") Integer idfetchsize, @QueryParam("fetchsize") Integer fetchsize, @QueryParam("threads") Integer threads) { SearchSession searchSession = Search.session( em ); MassIndexer indexer = searchSession.massIndexer( Page.class, User.class ) .dropAndCreateSchemaOnStart( true ) .typesToIndexInParallel( 2 ) .batchSizeToLoadObjects( fetchsize == null ? 200 : fetchsize ) .idFetchSize( idfetchsize == null ? 200 : idfetchsize ) .threadsToLoadObjects( threads == null ? 5 :threads ) .cacheMode( CacheMode.IGNORE ); // Cache is likely to do more harm than good in our case (very few relations) if ( limit != null ) { indexer.limitIndexedObjectsTo( limit ); } indexer.start(); return Response.accepted().build(); }
Example #3
Source File: LibraryResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@Transactional void onStart(@Observes StartupEvent ev) throws InterruptedException { // only reindex if we imported some content if (Book.count() > 0) { Search.session(em) .massIndexer() .startAndWait(); } }
Example #4
Source File: LibraryResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Path("author/search") @Transactional public List<Author> searchAuthors(@QueryParam String pattern, @QueryParam Optional<Integer> size) { List<Author> authors = Search.session(em) .search(Author.class) .where(f -> pattern == null || pattern.trim().isEmpty() ? f.matchAll() : f.simpleQueryString() .fields("firstName", "lastName", "books.title").matching(pattern)) .sort(f -> f.field("lastName_sort").then().field("firstName_sort")) .fetchHits(size.orElse(20)); return authors; }
Example #5
Source File: HibernateSearchTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@PUT @Path("/purge") @Produces(MediaType.TEXT_PLAIN) public String testPurge() { SearchSession searchSession = Search.session(entityManager); searchSession.workspace().purge(); return "OK"; }
Example #6
Source File: HibernateSearchTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@PUT @Path("/refresh") @Produces(MediaType.TEXT_PLAIN) public String testRefresh() { SearchSession searchSession = Search.session(entityManager); searchSession.workspace().refresh(); return "OK"; }
Example #7
Source File: HibernateSearchTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@GET @Path("/search-empty") @Produces(MediaType.TEXT_PLAIN) public String testSearchEmpty() { SearchSession searchSession = Search.session(entityManager); List<Person> person = searchSession.search(Person.class) .where(f -> f.matchAll()) .fetchHits(20); assertEquals(0, person.size()); return "OK"; }
Example #8
Source File: HibernateSearchTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@PUT @Path("/mass-indexer") @Produces(MediaType.TEXT_PLAIN) public String testMassIndexer() throws InterruptedException { SearchSession searchSession = Search.session(entityManager); searchSession.massIndexer().startAndWait(); return "OK"; }
Example #9
Source File: SearchIndexerImplITest.java From cia with Apache License 2.0 | 5 votes |
@Test @Transactional(timeout=30) public void testSearchIndex() throws Exception { final List<DocumentContentData> result = Search.session(entityManager).search(DocumentContentData.class).asEntity() .predicate(t -> t.match().fields("content").matching("programmering")).fetchHits(500); assertTrue("expect some result",result.size()> 0); }
Example #10
Source File: HibernatePageDaoImpl.java From hibernate-demos with Apache License 2.0 | 5 votes |
@Override public SearchResult<Page> search(String term, PageSort sort, int offset, int limit) { SearchSession searchSession = Search.session( getEm() ); return new SearchResult<>( searchSession.search( Page.class ) .where( f -> { if ( term == null || term.isEmpty() ) { return f.matchAll(); } else { return f.match() .field( "title" ).boost( 2.0f ) .field( "content" ) .matching( term ); } } ) .sort( f -> { switch ( sort ) { case TITLE: return f.field( "title_sort" ); case RELEVANCE: default: return f.score(); } } ) .fetch( offset, limit ) ); }
Example #11
Source File: ClientResource.java From hibernate-demos with Apache License 2.0 | 5 votes |
@POST @Path("/client/reindex") @Transactional(TxType.NEVER) public void reindex() throws InterruptedException { Search.mapping( entityManagerFactory ) .scope( Client.class ) .massIndexer() .startAndWait(); }
Example #12
Source File: ClientResource.java From hibernate-demos with Apache License 2.0 | 5 votes |
@GET @Path("/client/search") public List<ClientRetrieveDto> search(@QueryParam("terms") String terms) { List<Client> result = Search.session( Panache.getEntityManager() ) .search( Client.class ) .predicate( f -> f.simpleQueryString() .fields( "name", "assignedManager.name" ) .matching( terms ) .defaultOperator( BooleanOperator.AND ) ) .fetchHits( 20 ); return result.stream().map( mapper::toDto ).collect( Collectors.toList() ); }
Example #13
Source File: HibernateSearch6InstrumentationTest.java From apm-agent-java with Apache License 2.0 | 4 votes |
private HibernateOrmSearchQueryResultDefinitionContext<Dog> createDogSearch() { return Search.getSearchSession(entityManager) .search(Dog.class); }
Example #14
Source File: SearchIndexerImpl.java From cia with Apache License 2.0 | 4 votes |
@Override public void updateSearchIndex() throws InterruptedException { Search.session(entityManager).massIndexer().transactionTimeout(TIMEOUT_IN_SECONDS).startAndWait(); }
Example #15
Source File: AbstractGenericDAOImpl.java From cia with Apache License 2.0 | 2 votes |
/** * Gets the full text entity manager. * * @return the full text entity manager */ protected final SearchSession getFullTextEntityManager() { return Search.session(getEntityManager()); }