All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.FullTextSession Maven / Gradle / Ivy

There is a newer version: 5.11.12.Final
Show newest version
/*
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.search;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.search.query.engine.spi.QueryDescriptor;

/**
 * Extends the Hibernate {@link Session} with fulltext search and indexing capabilities.
 *
 * @author Emmanuel Bernard
 */
public interface FullTextSession extends Session {

	/**
	 * Create a fulltext query on top of a native Lucene query returning the matching objects
	 * of type entities and their respective subclasses.
	 *
	 * @param luceneQuery The native Lucene query to be run against the Lucene index.
	 * @param entities List of classes for type filtering. The query result will only return entities of
	 * the specified types and their respective subtype. If no class is specified no type filtering will take place.
	 *
	 * @return A FullTextQuery wrapping around the native Lucene query.
	 *
	 * @throws IllegalArgumentException if entityType is null or not a class or superclass annotated with @Indexed.
	 */
	FullTextQuery createFullTextQuery(org.apache.lucene.search.Query luceneQuery, Class... entities);

	/**
	 * Creates a fulltext query from the given query descriptor.
	 */
	FullTextQuery createFullTextQuery(QueryDescriptor descriptor, Class... entities);

	/**
	 * Force the (re)indexing of a given managed object.
	 * Indexation is batched per transaction: if a transaction is active, the operation
	 * will not affect the index at least until commit.
	 *
	 * Any {@link org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor} registered on the entity will be ignored:
	 * this method forces an index operation.
	 *
	 * @param  the type of the entity to index
	 * @param entity The entity to index - must not be null.
	 *
	 * @throws IllegalArgumentException if entity is null or not an @Indexed entity
	 */
	 void index(T entity);

	/**
	 * @return the SearchFactory instance.
	 */
	SearchFactory getSearchFactory();

	/**
	 * Remove the entity with the type entityType and the identifier id from the index.
	 * If id == null all indexed entities of this type and its indexed subclasses are deleted. In this
	 * case this method behaves like {@link #purgeAll(Class)}.
	 *
	 * Any {@link org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor} registered on the entity will be ignored:
	 * this method forces a purge operation.
	 *
	 * @param  the type of the entity to purge
	 * @param entityType The type of the entity to delete.
	 * @param id The id of the entity to delete.
	 *
	 * @throws IllegalArgumentException if entityType is null or not a class or superclass annotated with @Indexed.
	 */
	 void purge(Class entityType, Serializable id);

	/**
	 * Remove all entities from of particular class and all its subclasses from the index.
	 *
	 * Any {@link org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor} registered on the entity type will be ignored.
	 *
	 * @param  the type of the entity to purge
	 * @param entityType The class of the entities to remove.
	 *
	 * @throws IllegalArgumentException if entityType is null or not a class or superclass annotated with @Indexed.
	 */
	 void purgeAll(Class entityType);

	/**
	 * Flush all index changes forcing Hibernate Search to apply all changes to the index not waiting for the batch limit.
	 */
	void flushToIndexes();

	/**
	 * Creates a MassIndexer to rebuild the indexes of some
	 * or all indexed entity types.
	 * Instances cannot be reused.
	 *
	 * Any {@link org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor} registered on the entity types are applied: each instance will trigger
	 * an {@link org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor#onAdd(Object)} event from where you can customize the indexing operation.
	 *
	 * @param types optionally restrict the operation to selected types
	 * @return a new MassIndexer
	 */
	MassIndexer createIndexer(Class... types);

	/**
	 * {@inheritDoc}
	 */
	@Override
	FullTextSharedSessionBuilder sessionWithOptions();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy