You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过Agresso QueryEngineService对列进行搜索/筛选?

如何通过Agresso QueryEngineService实现列搜索/筛选

首先明确:你完全可以通过QueryEngineService实现列的搜索和筛选,你当前的代码问题在于只是获取了默认的搜索条件和结果选项,但没有添加具体的筛选规则。下面我会结合你的代码,给出两种可行的实现方式:

方法一:使用SearchCriteriaPropertiesList添加筛选条件

SearchCriteriaPropertiesList适合针对单个列设置简单的筛选规则(等于、包含、大于等)。你需要在获取默认的SearchCriteria后,修改其SearchCriteriaPropertiesList,添加具体的筛选条件:

QueryEngineService.TemplateList templateList = QueryEngineService.GetTemplateList(null, null, Credentials);
var template = templateList.TemplateHeaderList.FirstOrDefault(x => x.Name == strViewName);
if (template == null) return null;

// 获取默认搜索条件
QueryEngineService.SearchCriteria searchProp = QueryEngineService.GetSearchCriteria(template.TemplateId, false, Credentials);

// 清空默认条件(如果不需要保留),然后添加自定义筛选规则
searchProp.SearchCriteriaPropertiesList.Clear();

// 示例:筛选"CustomerId"列等于"12345"
QueryEngineService.SearchCriteriaProperty filterProp = new QueryEngineService.SearchCriteriaProperty();
filterProp.ColumnName = "CustomerId"; // 确保是模板中实际的列名
filterProp.Operator = QueryEngineService.SearchOperator.Equal; // 可选操作符:Equal、Contains、GreaterThan等
filterProp.Value = "12345"; // 对应筛选值
searchProp.SearchCriteriaPropertiesList.Add(filterProp);

// 设置结果选项
QueryEngineService.TemplateResultOptions options = QueryEngineService.GetTemplateResultOptions(Credentials);
options.RemoveHiddenColumns = true;

// 组装输入参数
QueryEngineService.InputForTemplateResult input = new QueryEngineService.InputForTemplateResult();
input.TemplateResultOptions = options;
input.TemplateId = template.TemplateId;
input.SearchCriteriaPropertiesList = searchProp.SearchCriteriaPropertiesList;

// 获取筛选后的结果
QueryEngineService.TemplateResultAsDataSet result = QueryEngineService.GetTemplateResultAsDataSet(input, Credentials);
return result.TemplateResult;

方法二:使用TemplateResultOptions.Filter设置复杂过滤表达式

如果需要多条件组合(比如AND/OR逻辑),可以使用TemplateResultOptions.Filter,它支持类似SQL WHERE子句的语法(注意要使用模板中的列名,而非数据库表列名):

QueryEngineService.TemplateList templateList = QueryEngineService.GetTemplateList(null, null, Credentials);
var template = templateList.TemplateHeaderList.FirstOrDefault(x => x.Name == strViewName);
if (template == null) return null;

// 获取默认搜索条件(此处无需修改SearchCriteriaPropertiesList)
QueryEngineService.SearchCriteria searchProp = QueryEngineService.GetSearchCriteria(template.TemplateId, false, Credentials);

// 设置结果选项,添加复杂Filter表达式
QueryEngineService.TemplateResultOptions options = QueryEngineService.GetTemplateResultOptions(Credentials);
options.RemoveHiddenColumns = true;
// 示例:筛选CustomerId等于12345 且 Amount大于1000
options.Filter = "CustomerId = '12345' AND Amount > 1000";

// 组装输入参数
QueryEngineService.InputForTemplateResult input = new QueryEngineService.InputForTemplateResult();
input.TemplateResultOptions = options;
input.TemplateId = template.TemplateId;
input.SearchCriteriaPropertiesList = searchProp.SearchCriteriaPropertiesList;

// 获取筛选后的结果
QueryEngineService.TemplateResultAsDataSet result = QueryEngineService.GetTemplateResultAsDataSet(input, Credentials);
return result.TemplateResult;

注意事项

  • 确保你使用的ColumnName是模板中定义的显示列名或内部列名,可以通过查看Agresso模板配置确认,避免拼写错误或大小写问题。
  • 使用Filter表达式时,注意数据类型匹配:字符串值需要用单引号包裹,数值类型直接书写即可。
  • 部分Agresso版本可能对Filter语法有细微差异,如果遇到问题,可以尝试简化表达式逐步测试。

内容的提问来源于stack exchange,提问作者Jimmy Mattsson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:50:40