简体   繁体   English

如何使用结构化前缀运算符和 AWS CloudSearch 进行通配符搜索

[英]How to do wildcard search using structured prefix operator with AWS CloudSearch

I've currently migrating to the 2013 Cloudsearch API (from the 2011 API).我目前正在迁移到 2013 Cloudsearch API(来自 2011 API)。 Previously, I had been using a wildcard prefix with my searches, like this:以前,我一直在搜索中使用通配符前缀,如下所示:

bq=(and 'first secon*')  

My queries sometimes include facet options, which is why I use the boolean query syntax and not the simple version.我的查询有时包括方面选项,这就是为什么我使用布尔查询语法而不是简单版本的原因。

I've created a new cloudsearch instance using the 2013 engine and indexed it.我使用 2013 引擎创建了一个新的 cloudsearch 实例并将其编入索引。 The bq parameter is gone now, so I have to use the q parameter with the q.parser=structured parameter to get the same functionality. bq参数现在没有了,所以我必须使用q参数和q.parser=structured参数来获得相同的功能。 When I query with something like this:当我用这样的东西查询时:

q.parser=simple&q=first secon*

...I get back a load of results. ...我得到了很多结果。 But when I query with this:但是当我用这个查询时:

q.parser=structured&q=(prefix 'first secon')

...I get no hits. ......我没有命中。 I don't get an error, just no results found.我没有收到错误,只是没有找到结果。 Am I doing something wrong?难道我做错了什么?

I've just realized that if I do a prefix search for the word firs with the 2013 API, the prefix search seems to be working.我刚刚意识到,如果我使用 2013 API 对单词firs进行前缀搜索,则前缀搜索似乎有效。 But if I have any more than a single term in the query eg first secon then the prefix search does not work.但是,如果我在查询中只有一个以上的术语,例如first secon则前缀搜索不起作用。 So how is this accomplished using the structured prefix operator?那么这是如何使用结构化前缀运算符完成的呢?

您需要为每个单独的查询词指定前缀运算符,例如:

q=(or (prefix 'firs') (prefix 'secon'))&q.parser=structured

If someones looking for JS code to solve this issue.如果有人在寻找 JS 代码来解决这个问题。 What you need to do is split the user input on space, and store them in an array.您需要做的是在空间上拆分用户输入,并将它们存储在一个数组中。 The join the words you want to query back together with pipes.将要查询的单词与管道连接在一起。

      var params = {
        query: ''
      };

      //Check for spaces
      let words = query.split(' ');
      let chunks = [];
      words.forEach(word => {
        chunks.push(`${word}* | ${word}`);
      })

      params.query = chunks.join(' | ');

      cloudsearch.search(params, function(err, data) {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      });

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

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