Hi all,
I am using Hibernate Search in my Spring+Hibernate web application, While i am using default analyzer[
@Field(index=Index.TOKENIZED,store=Store.YES)] Hibernate Search Indexing Data Nicely,.....But While i am using
custom Analyzer [
@Field(index=Index.TOKENIZED,analyzer=@Analyzer(definition="ngram"),store=Store.YES)] Hibernate Search does NOT performing INDEXING. I don't Know What is The Problem. Can anybody Help Me?
Here is my Entity
Code:
/Hibernate Search Annotations.
@AnalyzerDef(name = "ngram",tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = StandardFilterFactory.class),//Remove dots from acronyms and 's from words
@TokenFilterDef(factory = LowerCaseFilterFactory.class),//Lowercases all words
@TokenFilterDef(factory = StopFilterFactory.class),//Remove words (tokens) matching a list of stop words
@TokenFilterDef(factory = SnowballPorterFilterFactory.class,
params = {@Parameter(name = "language", value = "English")}),//Reduces a word to it's root in a given language. (eg. protect, protects, protection share the same root). Using such a filter allows searches matching related words.
@TokenFilterDef(factory =SynonymFilterFactory.class,
// expand all synonyms in the token stream
params = {@Parameter(name="expand",value="true")})
})
@Entity
@Table(name="CategoryMapping",catalog="dbname")
@Indexed
public class CategoryMapping implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name="sno" , nullable=false)
private BigInteger sno;
@Column(name="product_type", nullable=false)
//@Field(index=Index.TOKENIZED,store=Store.YES)
@Field(index=Index.TOKENIZED,analyzer=@Analyzer(definition="ngram"),store=Store.YES)
private String product_type;
@Column(name="category", nullable=false)
//@Field(index=Index.TOKENIZED,store=Store.YES)
@Field(index=Index.TOKENIZED,analyzer=@Analyzer(definition="ngram"),store=Store.YES)
private String category;
/**
* @return the sno
*/
public BigInteger getSno() {
return sno;
}
/**
* @param sno the sno to set
*/
public void setSno(BigInteger sno) {
this.sno = sno;
}
/**
* @return the product_type
*/
public String getProduct_type() {
return product_type;
}
/**
* @param product_type the product_type to set
*/
public void setProduct_type(String product_type) {
this.product_type = product_type;
}
/**
* @return the category
*/
public String getCategory() {
return category;
}
/**
* @param category the category to set
*/
public void setCategory(String category) {
this.category = category;
}
}
Here my custom Analyzer name in 'ngram'.
NOTE: i commented the Deafult '@Field' annotation .
and Indexing Code is
Code:
/**
* This method Indexes the CategoryMapping database.
*/
@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.REPEATABLE_READ)
public void indexCategoryMapping()throws HibernateException,NullPointerException,ParseException,
Exception{
logger.info("Indexing CategoryMapping Database.......");
Session session=null;
FullTextSession fullTextSession=null;
//Getting current session object.
session=sessionFactory.getCurrentSession();
if(session==null){
logger.info("session is null in IndexCategoryMapping");
throw new NullPointerException();
}
//Creating 'fullTextSession' Object.
fullTextSession = Search.getFullTextSession(session);
if(fullTextSession==null){
logger.info("fullTextSession is null in IndexCategoryMapping");
throw new NullPointerException();
}
@SuppressWarnings("unchecked")
List<CategoryMapping> categories = session.createQuery("from CategoryMapping as cm").list();
for (CategoryMapping cm : categories) {
fullTextSession.index(cm);
}
}
Thanks
raju.