Hibernate Search is not returning any results -
i doing experiments hibernate search. far been able create indexes , configurations stuff. indexes created , verified them using luke. when try search doesn't return result. faceting request works well.
entity
@entity @table(name = "user_profile") @root(name = "candidate") @xmlrootelement @indexed @analyzer(impl = standardanalyzer.class) public class profilebean implements serializable, datamodel { private static final long serialversionuid = 1l; @id @generatedvalue @element @documentid private integer id; @notnull @length(max = 25) @element(required=false) @column(name = "first_name") @field(index = index.yes,analyze = analyze.yes, store = store.yes) private string firstname; @column(name = "last_name") @notnull @length(max = 25) @element(required=false) @field(index = index.yes,analyze = analyze.yes, store = store.yes) private string lastname; @column(name = "email") @length(max = 25) @element @field(index = index.yes,analyze = analyze.yes, store = store.yes) private string email; @column(name = "city") @notnull @length(max = 30) @element(required=false) @field(index = index.yes,analyze = analyze.no, store = store.yes) private string city; @column(name = "country") @notnull @length(max = 25) @element(required=false) @field(index = index.yes,analyze = analyze.no, store = store.yes) private string country; @column(name = "occupation") @length(max = 25) @element(required=false) @field(index = index.yes,analyze = analyze.no, store = store.yes) private string occupation; }
indexing code
fulltextsession fts = org.hibernate.search.search.getfulltextsession(getsession()); list<profilebean> profiles = super.listall(); (profilebean item : profiles) { fts.index(item); //manually index item instance }
faceting search code (which works well)
fulltextsession fts = org.hibernate.search.search.getfulltextsession(getsession()); querybuilder builder = fts.getsearchfactory() .buildquerybuilder().forentity(profilebean.class).get(); facetingrequest cityfacetingrequest = builder.facet() .name("cityfaceting").onfield("city").discrete() .orderedby(facetsortorder.count_desc).includezerocounts(false) .createfacetingrequest(); query lucenequery = builder.all().createquery(); fulltextquery fulltextquery = fts.createfulltextquery(lucenequery, profilebean.class); facetmanager facetmanager = fulltextquery.getfacetmanager(); facetmanager.enablefaceting(cityfacetingrequest); list<facet> facets = facetmanager.getfacets("cityfaceting"); (facet f : facets) { system.out.println(f.getvalue() + " (" + f.getcount() + ")"); list<profilebean> profiles = fts.createfulltextquery( f.getfacetquery(),profilebean.class).list(); (final profilebean p : profiles) { system.out.println(p.getfirstname() + " (" + p.getlastname() + ")"); } }
searching code not working
fulltextsession fts = org.hibernate.search.search.getfulltextsession(getsession()); querybuilder builder = fts.getsearchfactory() .buildquerybuilder().forentity(profilebean.class).get(); query query = builder.keyword(). onfields("occupation", "city", "country"). matching("engineer").createquery(); fulltextquery fulltextquery = fts.createfulltextquery(query, profilebean.class); list<profilebean> profiles = fulltextquery.list(); for(profilebean bean: profiles){ system.out.println("first name: "+bean.getfirstname()+" ,last name:"+bean.getlastname()+" ,occupation:"+bean.getoccupation()); }
i tried types of lucene queries nothing works highly regarded.
answer above question is:
if set analyze attribute of @field annotation no won't tokenized(would saved is, case sensitive). searchable fields should set analyze = analyze.yes please note facet search on these fields won't work!
Comments
Post a Comment