dreamfactory:使用多个过滤器查询记录
dreamfactory : Querying records with multiple filters
我正在开发电子商务 android 应用程序。我正在尝试基于多个过滤器使用 dreamfactory API 为 android 获取记录。
使用名为 GetProductsBySubCatIdTask 的 AsyncTask
public class GetProductsBySubCatIdTask extends BaseAsyncRequest {
Context context;
public Products productsRec;
int subCatId;
String sort_str,fltr_str;
public GetProductsBySubCatIdTask(Context context, int subCataId, String sort_str, String fltr_str){
this.context = context;
this.subCatId = subCataId;
this.sort_str = sort_str;
this.fltr_str = fltr_str;
}
@Override
protected void doSetup() throws ApiException, JSONException {
callerName = "getProductsBySubCatId";
serviceName = AppConstants.DB_SVC;
endPoint = "product";
verb = "GET";
// filter to only select the contacts in this group
if(!TextUtils.isEmpty(fltr_str)){
fltr_str = "&&" + fltr_str;
}
else{
fltr_str = "";
}
queryParams = new HashMap<>();
queryParams.put("filter", "sub_category_id=" + subCatId + fltr_str);
queryParams.put("order", sort_str);
applicationApiKey = AppConstants.API_KEY;
sessionToken = PrefUtil.getString(context, AppConstants.SESSION_TOKEN);
}
@Override
protected void processResponse(String response) throws ApiException, JSONException {
//Log.d("Tang Ho"," >>>>> " + response);
productsRec =
(Products) ApiInvoker.deserialize(response, "", Products.class);
}
@Override
protected void onCompletion(boolean success) {
if(success && productsRec != null && productsRec.products.size() > 0){
Log.d("Tang Ho"," >>>>> Success");
}
}
}
我使用了在 class 之外构建并作为参数提供的过滤器,可能的过滤器是
unit_offerprice < unit_mrp<br>
unit_offerprice = unit_mrp<br>
(unit_offerprice > 200) && (unit_offerprice > 500)<br>
unit_offerprice > 100<br>
unit_offerprice < 600<br>
以上所有过滤器都可以单独使用,也可以像 2 或 3 一样组合使用
unit_offerprice < unit_mrp && unit_offerprice > 100
将字符串中的符号转义后如
unit_offerprice%3Cunit_mrp
无法获得想要的结果,
在文档中搜索但没有找到确切的东西。
可能的解决方案是什么?
如果您的过滤器有多个条件,则每个条件都需要放在括号 () 内。此外,使用 and 连接过滤器的正确语法是 AND,而不是 &&。
支持的逻辑运算符有 AND、OR 和 NOT。
在你的例子中,这个:
unit_offerprice < unit_mrp && unit_offerprice > 100
应该是这样的:
(unit_offerprice < unit_mrp) AND (unit_offerprice > 100)
查看文档的以下部分:
http://wiki.dreamfactory.com/DreamFactory/Features/Database/Records#Filtering_Records
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Querying_records_with_logical_filters
DreamFactory 还提供许多官方支持渠道,包括用户论坛。 http://www.dreamfactory.com/support
已通过为多个过滤器添加括号解决此问题。
但是使用特殊字符(如 <、>)时出现问题,并且
这需要
编码为 %3C(<)和 %3E(>),
用于过滤的字符串是:
"(unit_offerprice>100)AND(unit_offerprice<500)"
编码形式为:
"(unit_offerprice%3E100)AND(unit_offerprice%3C500)"
我正在开发电子商务 android 应用程序。我正在尝试基于多个过滤器使用 dreamfactory API 为 android 获取记录。
使用名为 GetProductsBySubCatIdTask 的 AsyncTask
public class GetProductsBySubCatIdTask extends BaseAsyncRequest {
Context context;
public Products productsRec;
int subCatId;
String sort_str,fltr_str;
public GetProductsBySubCatIdTask(Context context, int subCataId, String sort_str, String fltr_str){
this.context = context;
this.subCatId = subCataId;
this.sort_str = sort_str;
this.fltr_str = fltr_str;
}
@Override
protected void doSetup() throws ApiException, JSONException {
callerName = "getProductsBySubCatId";
serviceName = AppConstants.DB_SVC;
endPoint = "product";
verb = "GET";
// filter to only select the contacts in this group
if(!TextUtils.isEmpty(fltr_str)){
fltr_str = "&&" + fltr_str;
}
else{
fltr_str = "";
}
queryParams = new HashMap<>();
queryParams.put("filter", "sub_category_id=" + subCatId + fltr_str);
queryParams.put("order", sort_str);
applicationApiKey = AppConstants.API_KEY;
sessionToken = PrefUtil.getString(context, AppConstants.SESSION_TOKEN);
}
@Override
protected void processResponse(String response) throws ApiException, JSONException {
//Log.d("Tang Ho"," >>>>> " + response);
productsRec =
(Products) ApiInvoker.deserialize(response, "", Products.class);
}
@Override
protected void onCompletion(boolean success) {
if(success && productsRec != null && productsRec.products.size() > 0){
Log.d("Tang Ho"," >>>>> Success");
}
}
}
我使用了在 class 之外构建并作为参数提供的过滤器,可能的过滤器是
unit_offerprice < unit_mrp<br>
unit_offerprice = unit_mrp<br>
(unit_offerprice > 200) && (unit_offerprice > 500)<br>
unit_offerprice > 100<br>
unit_offerprice < 600<br>
以上所有过滤器都可以单独使用,也可以像 2 或 3 一样组合使用
unit_offerprice < unit_mrp && unit_offerprice > 100
将字符串中的符号转义后如
unit_offerprice%3Cunit_mrp
无法获得想要的结果, 在文档中搜索但没有找到确切的东西。
可能的解决方案是什么?
如果您的过滤器有多个条件,则每个条件都需要放在括号 () 内。此外,使用 and 连接过滤器的正确语法是 AND,而不是 &&。 支持的逻辑运算符有 AND、OR 和 NOT。
在你的例子中,这个:
unit_offerprice < unit_mrp && unit_offerprice > 100
应该是这样的:
(unit_offerprice < unit_mrp) AND (unit_offerprice > 100)
查看文档的以下部分: http://wiki.dreamfactory.com/DreamFactory/Features/Database/Records#Filtering_Records http://wiki.dreamfactory.com/DreamFactory/Tutorials/Querying_records_with_logical_filters
DreamFactory 还提供许多官方支持渠道,包括用户论坛。 http://www.dreamfactory.com/support
已通过为多个过滤器添加括号解决此问题。
但是使用特殊字符(如 <、>)时出现问题,并且 这需要
编码为 %3C(<)和 %3E(>), 用于过滤的字符串是:
"(unit_offerprice>100)AND(unit_offerprice<500)"
编码形式为:
"(unit_offerprice%3E100)AND(unit_offerprice%3C500)"