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

org.hibernate.search.cfg.AnalyzerDefMapping Maven / Gradle / Ivy

/*
 * 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.HashMap;
import java.util.Map;

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

/**
 * @author Emmanuel Bernard
 */
public class AnalyzerDefMapping {
	private SearchMapping mapping;
	private Map analyzerDef;
	private Map tokenizer;

	AnalyzerDefMapping(String name, Class tokenizerFactory, SearchMapping mapping) {
		this.mapping = mapping;
		this.analyzerDef = new HashMap();
		mapping.addAnalyzerDef( analyzerDef );
		analyzerDef.put( "name", name );
		tokenizer = new HashMap();
		tokenizer.put( "factory", tokenizerFactory );
		analyzerDef.put( "tokenizer", tokenizer );
	}

	/**
	 * {@code @TokenizerDef(, ... params={@Parameter(name="name", value="value"), ...}) }
	 */
	public AnalyzerDefMapping tokenizerParam(String name, String value) {
		Map param = SearchMapping.addElementToAnnotationArray( tokenizer, "params" );
		param.put( "name", name );
		param.put( "value", value );
		return this;
	}

	/**
	 * {@code @TokenFilterDef(factory=factory) }
	 */
	public TokenFilterDefMapping filter(Class factory) {
		return new TokenFilterDefMapping( factory, analyzerDef, mapping );
	}

	public AnalyzerDefMapping analyzerDef(String name, Class tokenizerFactory) {
		return new AnalyzerDefMapping( name, tokenizerFactory, mapping );
	}

	public EntityMapping entity(Class entityType) {
		return new EntityMapping( entityType, mapping );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy