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

org.hibernate.search.cfg.SearchMapping 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.cfg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.lucene.analysis.util.TokenizerFactory;

/**
 * Allows to configure indexing and search related aspects of a domain model using a fluent Java API. This API can be
 * used instead of or in conjunction with the annotation based configuration via
 * {@link org.hibernate.search.annotations.Indexed} etc. In case of conflicts the programmatic configuration for an
 * element takes precedence over the annotation-based configuration.
 * 

* Users can select a {@link SearchMapping} implementation through the * {@link org.hibernate.search.cfg.Environment#MODEL_MAPPING configuration properties}. * * @author Emmanuel Bernard */ public class SearchMapping { private final Set> analyzerDefs = new HashSet>(); private final Set> normalizerDefs = new HashSet>(); private final Set> fullTextFilterDefs = new HashSet>(); private final Map, EntityDescriptor> entities = new HashMap, EntityDescriptor>(); public Set> getAnalyzerDefs() { return analyzerDefs; } public Set> getNormalizerDefs() { return normalizerDefs; } public Set> getFullTextFilterDefs() { return fullTextFilterDefs; } public EntityDescriptor getEntityDescriptor(Class entityType) { return entities.get( entityType ); } public Set> getMappedEntities() { return entities.keySet(); } /** * @deprecated See {@link org.hibernate.search.annotations.AnalyzerDef} */ @Deprecated public AnalyzerDefMapping analyzerDef(String name, Class tokenizerFactory) { return analyzerDef( name, "", tokenizerFactory ); } /** * @deprecated See {@link org.hibernate.search.annotations.AnalyzerDef} */ @Deprecated public AnalyzerDefMapping analyzerDef(String name, String tokenizerName, Class tokenizerFactory) { return new AnalyzerDefMapping( name, tokenizerName, tokenizerFactory, this ); } /** * @deprecated See {@link org.hibernate.search.annotations.AnalyzerDef} */ @Deprecated public NormalizerDefMapping normalizerDef(String name) { return new NormalizerDefMapping( name, this ); } public EntityMapping entity(Class entityType) { return new EntityMapping( entityType, this ); } public FullTextFilterDefMapping fullTextFilterDef(String name, Class impl) { return new FullTextFilterDefMapping( this, name, impl ); } /** * eg @Containing(things={@Thing(...), @Thing(...)} * Map addedThing = addElementToAnnotationArray(containing, "things"); */ static Map addElementToAnnotationArray(Map containingAnnotation, String attributeName) { @SuppressWarnings("unchecked") List> array = (List>) containingAnnotation.get( attributeName ); if ( array == null ) { array = new ArrayList>(); containingAnnotation.put( attributeName, array ); } Map param = new HashMap(); array.add( param ); return param; } void addAnalyzerDef(Map analyzerDef) { analyzerDefs.add( analyzerDef ); } void addNormalizerDef(Map normalizerDef) { normalizerDefs.add( normalizerDef ); } EntityDescriptor getEntity(Class entityType) { EntityDescriptor entityDescriptor = entities.get( entityType ); if ( entityDescriptor == null ) { entityDescriptor = new EntityDescriptor( ); entities.put( entityType, entityDescriptor ); } return entityDescriptor; } void addFulltextFilterDef(Map fullTextFilterDef) { fullTextFilterDefs.add( fullTextFilterDef ); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy