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.CharFilterFactory;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.analysis.util.TokenizerFactory;

/**
 * @author Emmanuel Bernard
 * @deprecated See {@link org.hibernate.search.annotations.AnalyzerDef}
 */
@Deprecated
public class AnalyzerDefMapping {
	private SearchMapping mapping;
	private Map analyzerDef;
	private Map tokenizer;

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

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

	/**
	 * {@code @CharFilterDef(factory=factory) }
	 * @param factory the {@link CharFilterFactory}
	 * @return a new {@link CharFilterDefMapping}
	 */
	public CharFilterDefMapping charFilter(Class factory) {
		return charFilter( "", factory );
	}

	/**
	 * {@code @CharFilterDef(name=name, factory=factory) }
	 * @param name the char filter name
	 * @param factory the {@link CharFilterFactory}
	 * @return a new {@link CharFilterDefMapping}
	 */
	public CharFilterDefMapping charFilter(String name, Class factory) {
		return new CharFilterDefMapping( name, factory, analyzerDef, mapping );
	}

	/**
	 * {@code @TokenFilterDef(factory=factory) }
	 * @param factory the {@link TokenFilterFactory}
	 * @return a new {@link TokenFilterDefMapping}
	 */
	public TokenFilterDefMapping filter(Class factory) {
		return filter( "", factory );
	}

	/**
	 * {@code @TokenFilterDef(name=name, factory=factory) }
	 * @param name the token filter name
	 * @param factory the {@link TokenFilterFactory}
	 * @return a new {@link TokenFilterDefMapping}
	 */
	public TokenFilterDefMapping filter(String name, Class factory) {
		return new TokenFilterDefMapping( factory, analyzerDef, mapping );
	}

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

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

	public NormalizerDefMapping normalizerDef(String name) {
		return new NormalizerDefMapping( name, mapping );
	}

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

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy