Skip to content

Commit 08eb444

Browse files
authored
Merge pull request #103908 from brjohnstmsft/search-filter-escape
[Azure Cognitive Search] Clarify string escaping
2 parents af86f21 + 3352ea5 commit 08eb444

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

articles/search/query-lucene-syntax.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: brjohnstmsft
88
ms.author: brjohnst
99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 11/04/2019
11+
ms.date: 02/10/2020
1212
translation.priority.mt:
1313
- "de-de"
1414
- "es-es"
@@ -26,6 +26,9 @@ translation.priority.mt:
2626

2727
You can write queries against Azure Cognitive Search based on the rich [Lucene Query Parser](https://lucene.apache.org/core/6_6_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html) syntax for specialized query forms: wildcard, fuzzy search, proximity search, regular expressions are a few examples. Much of the Lucene Query Parser syntax is [implemented intact in Azure Cognitive Search](search-lucene-query-architecture.md), with the exception of *range searches* which are constructed in Azure Cognitive Search through `$filter` expressions.
2828

29+
> [!NOTE]
30+
> The full Lucene syntax is used for query expressions passed in the **search** parameter of the [Search Documents](https://docs.microsoft.com/rest/api/searchservice/search-documents) API, not to be confused with the [OData syntax](query-odata-filter-orderby-syntax.md) used for the [$filter](search-filters.md) parameter of that API. These different syntaxes have their own rules for constructing queries, escaping strings, and so on.
31+
2932
## How to invoke full parsing
3033

3134
Set the `queryType` search parameter to specify which parser to use. Valid values include `simple|full`, with `simple` as the default, and `full` for Lucene.

articles/search/query-odata-filter-orderby-syntax.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: brjohnstmsft
88
ms.author: brjohnst
99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 11/04/2019
11+
ms.date: 02/10/2020
1212
translation.priority.mt:
1313
- "de-de"
1414
- "es-es"
@@ -118,6 +118,17 @@ The following table shows examples of constants for each of the data types suppo
118118
| `Edm.Int64` | `283032927235` |
119119
| `Edm.String` | `'hello'` |
120120

121+
### Escaping special characters in string constants
122+
123+
String constants in OData are delimited by single quotes. If you need to construct a query with a string constant that might itself contain single quotes, you can escape the embedded quotes by doubling them.
124+
125+
For example, a phrase with an unformatted apostrophe like "Alice's car" would be represented in OData as the string constant `'Alice''s car'`.
126+
127+
> [!IMPORTANT]
128+
> When constructing filters programmatically, it's important to remember to escape string constants that come from user input. This is to mitigate the possibility of [injection attacks](https://wikipedia.org/wiki/SQL_injection), especially when using filters to implement [security trimming](search-security-trimming-for-azure-search.md).
129+
130+
### Constants syntax
131+
121132
The following EBNF ([Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)) defines the grammar for most of the constants shown in the above table. The grammar for geo-spatial types can be found in [OData geo-spatial functions in Azure Cognitive Search](search-query-odata-geo-spatial-functions.md).
122133

123134
<!-- Upload this EBNF using https://bottlecaps.de/rr/ui to create a downloadable railroad diagram. -->

articles/search/query-simple-syntax.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: brjohnstmsft
88
ms.author: brjohnst
99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 11/04/2019
11+
ms.date: 02/10/2020
1212
translation.priority.mt:
1313
- "de-de"
1414
- "es-es"
@@ -26,8 +26,10 @@ translation.priority.mt:
2626

2727
Azure Cognitive Search implements two Lucene-based query languages: [Simple Query Parser](https://lucene.apache.org/core/6_6_1/queryparser/org/apache/lucene/queryparser/simple/SimpleQueryParser.html) and the [Lucene Query Parser](https://lucene.apache.org/core/6_6_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html). In Azure Cognitive Search, the simple query syntax excludes the fuzzy/slop options.
2828

29-
> [!NOTE]
30-
> Azure Cognitive Search provides an alternative [Lucene Query Syntax](query-lucene-syntax.md) for more complex queries. To learn more about query parsing architecture and benefits of each syntax, see [How full text search works in Azure Cognitive Search](search-lucene-query-architecture.md).
29+
> [!NOTE]
30+
> The simple query syntax is used for query expressions passed in the **search** parameter of the [Search Documents](https://docs.microsoft.com/rest/api/searchservice/search-documents) API, not to be confused with the [OData syntax](query-odata-filter-orderby-syntax.md) used for the [$filter](search-filters.md) parameter of that API. These different syntaxes have their own rules for constructing queries, escaping strings, and so on.
31+
>
32+
> Azure Cognitive Search provides an alternative [full Lucene query syntax](query-lucene-syntax.md) for more complex queries in the **search** parameter. To learn more about query parsing architecture and benefits of each syntax, see [How full text search works in Azure Cognitive Search](search-lucene-query-architecture.md).
3133
3234
## How to invoke simple parsing
3335

0 commit comments

Comments
 (0)