RE: DDMFormInstanceRecord Search Problem

huang sunny, modified 6 Years ago. Junior Member Posts: 56 Join Date: 1/17/11 Recent Posts
HI,ALL.

I use BooleanQuery for DDMFormInstanceRecord Search. It works well when keywords is English, and  do not return expected results when keywords is Chinese.

At the same time, the returned result automatically filters the groupID, how can I get all the results, not the records in a group.

How to solve the above two problems.

Thanks

    protected void setDDMFormInstanceRecordSearchResults(
        FormInstanceRecordSearch formInstanceRecordSearch) {

    &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;List<ddmforminstancerecord> results = null;

&nbsp;    &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int status = WorkflowConstants.STATUS_ANY;

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SearchContext searchContext = getSearchContext(status);

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BooleanQuery booleanQuery = new BooleanQueryImpl();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;addExactRequiredTerm(booleanQuery,Field.STATUS, String.valueOf(WorkflowConstants.STATUS_APPROVED));
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;addExactRequiredTerm(booleanQuery,"ddm__keyword__89173__campanyeurDKk_zh_CN", "shanghai"); // return expected results:)
                addExactRequiredTerm(booleanQuery,"ddm__keyword__89173__campanyeurDKk_zh_CN", "上海"); // DO NOT return expected results:(
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (ParseException e) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// TODO Auto-generated catch block
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e.printStackTrace();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}


&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BooleanClause booleanClause = BooleanClauseFactoryUtil.create(
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;booleanQuery, BooleanClauseOccur.MUST.getName());
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setBooleanClauses(new BooleanClause[] {booleanClause});
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BaseModelSearchResult<ddmforminstancerecord> baseModelSearchResult =
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;_ddmFormInstanceRecordLocalService.searchFormInstanceRecords(
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext);

&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;results = baseModelSearchResult.getBaseModels();

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;formInstanceRecordSearch.setResults(results);
}

&nbsp;&nbsp; &nbsp; &nbsp;protected void addExactRequiredTerm(BooleanQuery query,String field,String value)throws ParseException {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TermQueryImpl termQuery = new TermQueryImpl(new QueryTermImpl(field,value));
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;query.add(termQuery,BooleanClauseOccur.MUST);
&nbsp;&nbsp; &nbsp; }


&nbsp;&nbsp; &nbsp;protected SearchContext getSearchContext(int status) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SearchContext searchContext = SearchContextFactory.getInstance(
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PortalUtil.getHttpServletRequest(_renderRequest));

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setAttribute(Field.STATUS, status);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setAttribute(
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"formInstanceId", _ddmFormInstance.getFormInstanceId());
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setEnd(searchContext.getEnd());
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setKeywords(getKeywords());
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;searchContext.setStart(searchContext.getStart());

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return searchContext;
&nbsp;&nbsp; &nbsp;}
</ddmforminstancerecord></ddmforminstancerecord>
huang sunny, modified 6 Years ago. Junior Member Posts: 56 Join Date: 1/17/11 Recent Posts
I have solved this problem.

In the build.gradle, add the code.

tasks.withType(JavaCompile) {
 options.encoding = 'UTF-8'
}

hope to help someone in need.