org.hibernate.search.mapper.orm.session.SearchSession Java Examples
The following examples show how to use
org.hibernate.search.mapper.orm.session.SearchSession.
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: 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 #4
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 #5
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 #6
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 #7
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 #8
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()); }