简体   繁体   English

如何将php数组编码为Amazon CloudSearch filterquery

[英]How to encode php array to Amazon CloudSearch filterquery

I have an array of fields & values that I wish to pass to the Amazon CloudSearchDomain as a filterQuery argument using one or both the 'and' or 'or' operators. 我有一组字段和值,希望使用“ and”或“ or”运算符之一或两者作为filterQuery参数传递给Amazon CloudSearchDomain。

For example, I'd like to pass a single 'and' field (a category) and a second 'and' field which is comprised of several 'or' values: 例如,我想传递一个'and'字段(一个类别)和第二个'and'字段,该字段由多个'or'值组成:

$filters = array(
   'category' => 'cat name',
   'colour'   => array(
      'red',
      'green'
   )
);

I have tried: 我努力了:

$results = $cloudSearchClient->search(array(
   'filterQuery' => "(and(category:'cat name') (or (colour:'red') (colour:'green')))"
));

So the search would find items that match 'cat name' AND are red OR green 因此,搜索将找到与“猫名”匹配且为红色或绿色的项目

I can't seem to pass the correct syntax manually, and would then also like a good clean solution to convert the PHP array into the correct AWS syntax please. 我似乎无法手动传递正确的语法,然后也希望有一个很好的干净解决方案,请将PHP数组转换为正确的AWS语法。

You might want to check two things here. 您可能要在这里检查两件事。 First is when you filter within the facet array you are using the 'OR' operator and if you are filtering between two facet arrays you are using 'AND'. 首先是当您在构面数组中进行过滤时,您使用的是“ OR”运算符;如果要在两个构面数组之间进行过滤,则将使用“ AND”。 Judging by your usage you want to display the results when a user selects either "red" or "green". 根据您的使用情况判断,您想在用户选择“红色”或“绿色”时显示结果。 Eg. 例如。 filterQuery which you return should have the query --> "(or color:'red'(or color:'green'))" 您返回的filterQuery应该具有查询->“(或颜色:'红色'(或颜色:'绿色'))”

Second is monitor the query that gets passed to the aws URL. 其次是监视传递到aws URL的查询。 Your filter query might be correct but the URL string needs to appended with html encoded space. 您的过滤器查询可能是正确的,但URL字符串需要附加html编码的空格。 For example http://your-search-domain/2013-01-01/search?&q.parser=structured&q.options=%7Bsomefield%27%2C+%27&sort=something%20 &fq=%28or+color%3A%27red%27%28or+color%3A%27green%27%29%29 ....." 例如http:// your-search-domain / 2013-01-01 / search?&q.parser = structured&q.options =%7Bsomefield%27%2C +%27&sort = something%20 &fq =%28or + color%3A%27red %27%28or + color%3A%27green%27%29%29 .....“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM