-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Search a word that ends with 'es' does not fetch correct res
PostPosted: Sun Mar 11, 2012 1:30 am 
Newbie

Joined: Sun Mar 11, 2012 1:10 am
Posts: 2
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;
}

}

----------------------


Top
 Profile  
 
 Post subject: Re: Search a word that ends with 'es' does not fetch correct res
PostPosted: Mon Mar 12, 2012 6:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

one thing I noticed is that you are using a German stemmer, but you try to index/analyze the English apple. Have you checked what your analyzer actually indexes? You can do that by using org.hibernate.search.util.AnalyzerUtils#tokenizedTermValues which will provided the analyzer and the test to index a list of tokens as strings. Making sure that the stemming/indexing works is the first step.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search a word that ends with 'es' does not fetch correct res
PostPosted: Mon Mar 12, 2012 3:54 pm 
Newbie

Joined: Sun Mar 11, 2012 1:10 am
Posts: 2
Thanks for your suggestion. Will try it out.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.