I am trying to get some data using FlexibleSearchQuery
but it is responding empty result. If I set this query hac>Console>Flexible Search
I can get the data I am looking for.
Here is how I am writing query in java file.
sb.append(" SELECT {p:pk} ");
sb.append(" FROM {" + ProductModel._TYPECODE + " AS p} ");
sb.append(" WHERE {p:" + ProductModel.PK + " } IN ({{");
sb.append(" SELECT DISTINCT {pro:" + ProductModel.PK + "} ");
sb.append(" FROM {CategoryProductRelation AS cp},{" + ProductModel._TYPECODE + "! AS pro},{" + CategoryModel._TYPECODE
+ " AS c}");
sb.append(" WHERE {pro:" + ProductModel.PK + " } = {cp:target}");
sb.append(" AND {c:" + CategoryModel.PK + " } = {cp:source}");
sb.append(" AND {c:" + CategoryModel.CODE + " } !=?categoryCode }})");
args.put("categoryCode", categoryCode);
if (args != null && !args.isEmpty())
{
searchQuery.addQueryParameters(args);
}
Here is how I call search
final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(sb.toString());
searchResult.getResult().size() >> retuns 0
If I type it in console
SELECT {p:pk} FROM { Product AS p} WHERE { p: pk } IN ({{
SELECT DISTINCT {pro: PK }
FROM
{CategoryProductRelation AS cp},
{Product AS pro},
{Category as c}
WHERE {pro: PK} = {cp:target}
AND {c:PK} = {cp:source}
AND {c:code} != '0101'}})
I get
PK
8796093579265
8796101804033
8796100165633
8796098428929
8796093153281
8796102361089
8796097052673
8796093808641
8796093972481
8796096823297
What am I doing wrong? Is there any difference console query and string query?