What is the difference between phrase and term in structured queries?
Asked Answered
C

2

11

How are phrase and term different in a Structured query?

I have this data in my CloudSearch domain:

{
    "guid": 9,
    "operating_systems": [
        "12345", "123"
    ],
    "manufacturer": "sealand",
    "model": "gaming tree whale plum",
    "identifier": "gaming tree whale plum",
    "type": "computer",
    "created_at": "1982-10-14T14:43:54Z"
}

"model" is type text, "identifier" is type literal, "created_at" is type date.

Let's make a few queries:

(phrase field=model 'tree whale')                match
(phrase field= identifier 'tree whale')          no match
(phrase 'tree whale')                            match
(phrase field=created_at '1982-10-14T14:43:54Z') match (this shouldn't match according to docs)

(term field=model 'tree whale')                match
(term field= identifier 'tree whale')          no match
(term 'tree whale')                            match
(term field=created_at '1982-10-14T14:43:54Z') match

Is there anything I can do with phrase that I can't do with term and vice-versa?

Congregationalism answered 10/3, 2016 at 8:57 Comment(1)
phrase matches exact order and term matches if the field contains the search term anywhere. "Sloppy phrases" are possible. Are you looking for any other specific differences?Damato
R
1

There is very little difference between the syntax and usage of term VS phrase. However, search behavior in handling phrases can be customized in ways terms cannot, which can be used to improve performance:

  • allowed operators
  • phraseFields
  • phraseSlop

Terms are intended for matching text fields, where phrases are intended for more complex searches.

Skip the web documentation, and just read all of the PDF: http://docs.aws.amazon.com/cloudsearch/latest/developerguide/cloudsearch-dg.pdf

Reforest answered 27/9, 2016 at 21:29 Comment(3)
When you say phrases are intended for more complex searches what do you mean? I would have thought that phrases are more strict and less flexible when it comes to searching, so overall you could do less complex things with them.Isobar
I can only guess, as with any architecture greater rigidity allows for better performance, as well as more flexibility of components which depend on it. Ultimately, phrases become more flexible only when you consider the implications of aliases and equivalent terms. {citrus, lemon, orange} {large, big, huge} `(phrase "big lemon") would match all possible combinations.Reforest
with term it won't check each word, it will only check the whole.Reforest
I
2

In case anyone is wondering, turns out that a phrase search matches the entire phrase while a term search matches the terms which may be a phrase but may be words spread around the document. Example:

Text:

"model": gaming tree whale plum

The following hold:

(phrase field=model 'tree whale')                match
(phrase field=model 'tree plum')                 no match

(term field=model 'tree whale')                  match
(term field=model 'tree plum')                   match
Isobar answered 8/6, 2017 at 7:40 Comment(0)
R
1

There is very little difference between the syntax and usage of term VS phrase. However, search behavior in handling phrases can be customized in ways terms cannot, which can be used to improve performance:

  • allowed operators
  • phraseFields
  • phraseSlop

Terms are intended for matching text fields, where phrases are intended for more complex searches.

Skip the web documentation, and just read all of the PDF: http://docs.aws.amazon.com/cloudsearch/latest/developerguide/cloudsearch-dg.pdf

Reforest answered 27/9, 2016 at 21:29 Comment(3)
When you say phrases are intended for more complex searches what do you mean? I would have thought that phrases are more strict and less flexible when it comes to searching, so overall you could do less complex things with them.Isobar
I can only guess, as with any architecture greater rigidity allows for better performance, as well as more flexibility of components which depend on it. Ultimately, phrases become more flexible only when you consider the implications of aliases and equivalent terms. {citrus, lemon, orange} {large, big, huge} `(phrase "big lemon") would match all possible combinations.Reforest
with term it won't check each word, it will only check the whole.Reforest

© 2022 - 2024 — McMap. All rights reserved.