I am using Hibernate Search. Indexed column has 'Apple' as value, when I search with 'Apples' the query does not fetch records with 'Apple' as value. Also if the DB column value had 'Apple,Orange', search with 'Apple' as a key word does not fetch this record - Since it has ',' next to apple, it is ignored. If I introduce a space then it works. Please let me know if I am missing anything. Below is the code snippet.
----------- Search related code ---------------
FullTextSession fullTextSession = Search.getFullTextSession(this.getHibernateTemplate().getSessionFactory().getCurrentSession()); String[] fields = new String[]{"productName", "productDesc"};
// create native Lucene query MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_31, fields, fullTextSession.getSearchFactory().getAnalyzer("customanalyzer")); org.apache.lucene.search.Query query = parser.parse(searchStr);
// wrap Lucene query in a org.hibernate.Query org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Product.class); return hibQuery.list(); -------------- ---------------
------------- Hibernate Entity where Indexing is done -----------
@Entity(name = "Product") @Table(name = "PRODUCT") @Indexed @AnalyzerDef(name = "customanalyzer", tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class), filters = { @TokenFilterDef(factory = LowerCaseFilterFactory.class), @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = { @Parameter(name = "language", value = "German") }) }) public class Product implements java.io.Serializable {
private Long id; private String productName; private String productDesc; public Product() { }
@Id @GeneratedValue(strategy = IDENTITY) @DocumentId @Column(name = "ID", nullable = false) public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
@Column(name = "PRODUCTNAME", nullable = false) @Field(index=Index.TOKENIZED, store=Store.NO) @Analyzer(definition = "customanalyzer") public String getProductName() { return this.productName; }
public void setProductName(String productName) { this.productName = productName; }
@Column(name = "PRODUCTDESC") @Field(index=Index.TOKENIZED, store=Store.NO) @Analyzer(definition = "customanalyzer") public String getProductDesc() { return this.productDesc; }
public void setProductDesc(String productDesc) { this.productDesc = productDesc; }
}
----------------------
|