Browse Source
Merge pull request #17456 from abpframework/issue-17172
Docs: Support exact match in search
pull/17545/head
Engincan VESKE
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
22 additions and
5 deletions
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs
|
|
|
@ -143,6 +143,27 @@ namespace Volo.Docs.Documents.FullSearch.Elastic |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
ValidateElasticSearchEnabled(); |
|
|
|
|
|
|
|
FieldNameQueryBase query; |
|
|
|
// if context starts with " or ends with " then we search for exact match
|
|
|
|
if (context.StartsWith("\"") && context.EndsWith("\"")) |
|
|
|
{ |
|
|
|
context = context.Trim('"'); |
|
|
|
|
|
|
|
query = new MatchPhraseQuery |
|
|
|
{ |
|
|
|
Query = context |
|
|
|
}; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
query = new MatchQuery |
|
|
|
{ |
|
|
|
Query = context |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
query.Field = "content"; |
|
|
|
|
|
|
|
var request = new SearchRequest |
|
|
|
{ |
|
|
|
@ -152,11 +173,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic |
|
|
|
{ |
|
|
|
Must = new QueryContainer[] |
|
|
|
{ |
|
|
|
new MatchQuery |
|
|
|
{ |
|
|
|
Field = "content", |
|
|
|
Query = context |
|
|
|
} |
|
|
|
query, |
|
|
|
}, |
|
|
|
Filter = new QueryContainer[] |
|
|
|
{ |
|
|
|
|