Search code examples
sharepointsharepoint-search

boolean operators in KQL


I am reading reference for Keyword Query Language in Sharepoint Search and trying to figure out how AND and OR operators work. I am specifically interested in KQL, not FQL. I am trying to figure out answers to the following questions:

  1. What would this query return: worda wordb? I understand that documents containing both worda and wordb. If so then AND keyword seems to be the default. Then why does it exist at all?
  2. worda OR wordb AND wordc - in this query is wordb mandatory or optional?
  3. worda OR wordb wordc - is wordc mandatory here?

Solution

    1. using free-text query worda wordb AND operator is used by default. If you need OR operator in free-text query you must use it explicitly.
    2. In property queries like propertyA:"worda" propertyB:"wordb" OR operator is default and AND operator must be used explicitly.
    3. Mixing free-text and property queries AND default as well.
    4. AND operator has higher priority than OR. worda OR wordb wordc is the same as worda OR wordb AND wordc and it's the same as worda OR (wordb AND wordc). If you want different behavior you need use (worda OR wordb) AND wordc.