Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lucene query docs, fixing QueryStringQueryProvider (Lombiq Technologies: OCORE-93) #11561

Merged
merged 9 commits into from
Apr 22, 2022
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