Only Exact Search Matches for Quoted Phrases


(Tim White) #1

Hello -

I need to enable searches that return only exact matches for quoted phrases.

For example "Bank of America" should not return results that only contain "America" or "bank" as these are common words in the search corpus.

I have tried using escaped quotations, "Bank of America" as well as other various versions of quoting strings, and I continue to get non-exact matches.

Google does this quite well, I am trying to determine how to coerce SwiftType to do the same.

Thank you!


(Kellen Evan) #2

Hey Tim ~

Thanks for joining the community. :tada:

I've tested this locally within a demo Engine. Here's what I see...

A query without quotes, with highlight_fields:

 curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
  -H 'Content-Type: application/json' \
  -d '{
        "engine_key": "swiftype-api-example",
        "q": "Grumpy Cat",
        "highlight_fields":{
          "videos":{"title":{"size":60,"fallback":false}}
        }
      }' | jq

Result 1:

...
"title": "<em>Grumpy</em> <em>Cat</em> Does The Harlem Shake (Ad Free)"
...

Result 2:

...
"title": "Nyan <em>Cat</em> [original]"
...

I see partial matches -- but that's what we'd expect.

The same query with quotes:

curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json'   -H 'Content-Type: application/json'   -d '{
        "engine_key": "swiftype-api-example",
        "q": "\"Grumpy Cat\"",
        "highlight_fields":{
          "videos":{"title":{"size":60,"fallback":false}}
        }
      }' | jq

Result 1:

...
"title": "<em>Grumpy</em> <em>Cat</em> Does The Harlem Shake (Ad Free)"
...

I receive only one result as expected -- the exact match. It's highlighted whole.

It might be the escaping method. Perhaps you can share some similar queries, and we can get to the bottom of things.

Happy Friday,

Kellen


(Tim White) #3

Thank you! I think part of the challenge is that in the "Search Preview" in the Swiftype console, I have to enter those escaped quotes as well, which seems like a UI bug.

Also, checking my corpus, I still get results that aren't an exact match, they just have nothing highlighted. But I do get significantly fewer using escaped quotes, but it's not none. There are just too many articles that have "bank" and "America" in them. :frowning: