cancel
Showing results for 
Search instead for 
Did you mean: 

how to use flexible serach query in controller

Former Member
0 Kudos

"select {policynumber}" + "FROM {" + PolicyModel._TYPECODE + " } ";

in my controller code..policynumber is the column-name of the table and PolicyModel._TYPECODE is the table name stll its not working

Accepted Solutions (0)

Answers (6)

Answers (6)

bhaskarg2
Explorer
0 Kudos

Use the following query string to get policynumber.. queryString = "SELECT {policynumber} FROM {policy}"

Former Member
0 Kudos

Hi, It can be the issue with setting resultant class in the flexiblesearchquery also. viz, flexibleSearchquery.setResultClassList(Arrays.asList(String.class));

Former Member
0 Kudos

hi Srashti, please take into consideration to move your flexible search query to a lower level layer as others have suggested already. I assume you have a typo in your string concatenation causing your issue. You seem to lack a space before "FROM ". If you like to test your queries, you can use https://localhost:9002/console/flexsearch.

Former Member
0 Kudos

You should better create a dao class with an interface and extend from DefaultGenericDao class.

Interface Class

 public interface CorePolicyDao extends GenericDao<PolicyModel> {
     List<PolicyModel> search();
 }

DAO Class

 public class DefaultCorePolicyDao extends DefaultGenericDao<PolicyModel> implements CorePolicyDao {
     
     @Override
     public List<PolicyModel> search() {
         final String queryString = "SELECT {p.pk} FROM { Policy AS p }";
         
         FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
         
         return getFlexibleSearchService().<PolicyModel>search(query).getResult();
     }
 }


bhavirisetty
Active Participant
0 Kudos

Hi,

Executing flexiblequery in controller is not idle way,

However could you please share the error log and code to understand the issue.

Thanks

Former Member
0 Kudos

Hi Srashti,

Please check the API at https://help.hybris.com/6.2.0/api/commercesuite/index.html You need to use a FlexibleSearchQuery and specify the column types using setResultClassList. By default it's Item type.

Hope this helps, Cristian