How to use other Analyzer?
fvalente Dec 24, 2008 12:58 PMI'm using Hibernate Search. I can index and search properly. Now I'm trying to use the BrazilianAnalyzer, but it's not working.
Here is My code:
@AutoCreate @Name("searchController") @Scope(ScopeType.CONVERSATION) public class SearchController { @In private FullTextEntityManager entityManager; public void search(SearchData searchData) { String[] searchFields = {"fullName", "description", "summary", "title", "experience", "nickname", "qualifications", "keywords"}; MultiFieldQueryParser parser = new MultiFieldQueryParser(searchFields, new BrazilianAnalyzer()); parser.setAllowLeadingWildcard(true); try { String[] alist = searchPattern.split(" "); String queryString = ""; for (int i = 0; i < alist.length; i++) { queryString += (String) alist[i] + "~0.8"; } luceneQuery = parser.parse(queryString); } catch (ParseException e) { luceneQuery = null; } } public Pagination<StructuredDocument> getStructuredDocumentSearchResults() { if (luceneQuery != null) { FullTextQuery query = entityManager.createFullTextQuery(luceneQuery, StructuredDocument.class); query.enableFullTextFilter("structuredDocumentPublicStatus").setParameter("statusList", (new StructuredDocument()).getPublicStatusList()); return new Pagination<StructuredDocument>(this.filterByCommunity(query.getResultList(), identity.getCurrentCommunity()), getPageSize()); } return new YouKnowPagination<StructuredDocument>(); }
The search works perfectly, but it's not using the BrazilianAnalayzer. It uses the StandardAnalyzer instead. I know this because the brazilian stop words from the BrasilianAnalayser are not working. For instance, if i search de
, that is one brazilian stop word, I get several results, but if I search the
I get no results.
The only way I found to use BrazilianAnalayzer was to set the hibernate.search.analyzer in the pesistence.xml with org.apache.lucene.analysis.br.BrazilianAnalyzer.
The problem is that i need to use a different Analyzer if the user uses a different language to view the site e.g. if the person is viewing in English I want to use StandardAnalyzer insted of BrazilianAnalyzer.
Does anyone has an idea of how to progamatically change the analyser?