Skip to content

Commit

Permalink
Lucene query docs, fixing QueryStringQueryProvider (#11561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone authored Apr 22, 2022
1 parent 0c52d43 commit c6d8d64
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public Query CreateQuery(ILuceneQueryService builder, LuceneQueryContext context
}

var queryString = query["query"]?.Value<string>();
var defaultField = query["default_field"]?.Value<string>();
var defaultField = query["default_field"]?.Value<string>() ?? "";

var queryParser = new QueryParser(context.DefaultVersion, "", context.DefaultAnalyzer);
var queryParser = new QueryParser(context.DefaultVersion, defaultField, context.DefaultAnalyzer);
return queryParser.Parse(queryString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static IServiceCollection AddLuceneQueries(this IServiceCollection servic
services.AddSingleton<ILuceneQueryProvider, MatchQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, MatchAllQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, MatchPhraseQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, QueryStringQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, PrefixQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, QueryStringQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, RangeQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, RegexpQueryProvider>();
services.AddSingleton<ILuceneQueryProvider, SimpleQueryStringQueryProvider>();
Expand Down
76 changes: 60 additions & 16 deletions src/docs/reference/modules/Lucene/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ If you are running on Azure App Services or if you are using Elasticsearch, then
## Lucene Queries

The Lucene module provides a management UI and APIs for querying Lucene data using ElasticSearch Queries.
See : https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
See: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html

### Query Filters

Query filters are used to retrieve records from Lucene without taking care of the boost values on them. So, it is retrieving records just like a SQL database would do.

Here is an example of a filtered query :
Here is an example of a filtered query:

```json
{
Expand Down Expand Up @@ -116,23 +116,67 @@ With a must query in the bool Query. "finding specific content type(s)"
}
```

As you can see it allows to filter on multiple query types. All of the Query types that are available in Lucene or also filters.
Using the [`query_string` Lucene query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) with the [Query Parser Syntax](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html) (with syntax like `"exact match"` and `should AND contain`):

So you can use :
```json
{
"query":
{
"query_string": {
"query": "Content.ContentItem.FullText:\"exploration\""
}
}
}
```

Or in a way that you don't have to select the fields in the query (to allow users to do simpler search):

```json
{
"query":
{
"query_string": {
"query": "\"exploration\"",
"default_field": "Content.ContentItem.FullText"
}
}
}
```

`fuzzy`
`match`
`match_phrase`
`match_all`
`prefix`
`range`
`term`
`terms`
`wildcard`
`geo_distance`
`geo_bounding_box`
An alternative to the previous one with [`simple_query_string`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html):

```json
{
"query": {
"simple_query_string" : {
"query": "\"exploration\"",
"fields": ["Content.ContentItem.FullText"]
}
}
}
```

See ElasticSearch documentation for more details :
As you can see it allows to filter on multiple query types. All of the Query types that are available in Lucene are also filters.

So you can use:

- `bool`
- `geo_distance`
- `geo_bounding_box`
- `fuzzy`
- `match`
- `match_all`
- `match_phrase`
- `prefix`
- `query_string`
- `range`
- `regexp`
- `simple_query_string`
- `term`
- `terms`
- `wildcard`

See ElasticSearch documentation for more details:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html

## Video
Expand Down

0 comments on commit c6d8d64

Please sign in to comment.