Sunday, 15 February 2015

Hibernate lucene search include "the" and "a" as part of search -



Hibernate lucene search include "the" and "a" as part of search -

i'm using hibernate lucene index table movie. want index , search title column, including "the" , "a" part of search. ex, "the lastly man standing" "a wanted man". "the" , "a" relevant part of search results.

the problem if used index=index.un_tokenized in @field, no search can done. if used index.tokenized, can't search "the" , "a".

can give me guidance? in advance.

below code snippet:

@field(index = index.un_tokenized, store = store.no) <<< i've tried index.tokenized also. @column(name = "title") private string title;

code search:

@field(index = index.un_tokenized, store = store.no) <<< i've tried index.tokenized also.

@column(name = "title") private string title;

code search: fulltextentitymanager fulltextentitymanager = search.getfulltextentitymanager(entitymanager);

querybuilder querybuilder = fulltextentitymanager.getsearchfactory().buildquerybuilder().forentity(movie.class).get(); query lucenequery = querybuilder.keyword().onfield("title") .matching(title.tolowercase()).createquery();

return fulltextentitymanager.createfulltextquery(lucenequery, movie.class) .getresultlist();

i think 1 solution, defining analyzer. tokenize, not exclude mutual words "the". also, in search code, utilize method querybuilder.phrase() instead of keyword() search performed based on search phrase.

@analyzerdef(name = "custom", tokenizer = @tokenizerdef(factory = standardtokenizerfactory.class), filters = { @tokenfilterdef(factory = lowercasefilterfactory.class), @tokenfilterdef(factory = snowballporterfilterfactory.class, params = { @parameter(name = "language", value = "english") }) }) public class film {

@field(index = index.yes, analyze = analyze.yes, store = store.no) @analyzer(definition="custom") private string title;

... }

code search: querybuilder qb = fulltextentitymgr.getsearchfactory() .buildquerybuilder().forentity(movie.class).get();

query lucenequery = qb.phrase().onfield("title").sentence(term.tolowercase()).createquery(); javax.persistence.query query = fulltextentitymgr.createfulltextquery(lucenequery, movie.class);

hibernate search

No comments:

Post a Comment