RTF
RTF

Reputation: 6514

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). 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. 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. 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. But if I have any more than a single term in the query e.g. first secon then the prefix search does not work. So how is this accomplished using the structured prefix operator?

Upvotes: 2

Views: 4089

Answers (3)

beiliubei
beiliubei

Reputation: 183

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

you can try like this. phrase, confirm that must have first. and prefix with secon*

Upvotes: 0

blackops
blackops

Reputation: 2394

If someones looking for JS code to solve this issue. 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);
        }
      });

Upvotes: 0

alexroussos
alexroussos

Reputation: 2681

You need to specify the prefix operator for each separate query term, eg:

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

Upvotes: 8

Related Questions