Files
Umbraco-CMS/src/Umbraco.Cms.ManagementApi/Controllers/Search/SearcherSearchSearchController.cs
Nikolaj Geisle fb48ecb57f V11: merge dev to contrib (#13438)
* V11: add test flakyness reporting (#13386)

* update json-models-builders

* Add reporting to all before each loops

* Add commitId to env for pipelines

* Test reports correctly

* Bumb testhelper version

* Update playwright-testhelpers version

* Bumb playwright test-helper version

* Bumb playwright-testhelpers version

* Add AgentOs to yaml env

* Bumb playwright-testhelper version

* Try different AgentOS

* Revert "Try different AgentOS"

This reverts commit fc90620aef7af01ceffcdfbea7c9ef4dd02007f3.

* Revert logo test

* Add missing semicolons

* Update package-lock.json

* Add reports to Blocklist tests

Co-authored-by: Zeegaan <nge@umbraco.dk>

* V10: AllowedUploadFiles appsetting not working (#13408)

* Add new Settings

* Use new settings instead of old ones

* Implement AllowedUploadedFiles value to be copied to AllowedUplayedFileExtensions

* Obsolete old settings

* Rename DisallowedUploadFileExtensions

* Implement same fix for DisallowedUploadFiles

* Use new settings for backoffice server variables

* Update the correct setting

Co-authored-by: Zeegaan <nge@umbraco.dk>

* V11: Add  compatibility suppressions (#13425)

* Add suprressions

* Revert "Add suprressions"

This reverts commit 1c924ee967375870b6d86be9e9480ced0e22f8c7.

* Update CompatibilitySuppressions.xml

Co-authored-by: Ronald Barendse <ronald@barend.se>

* Bump socket.io-parser from 4.0.4 to 4.0.5 in /src/Umbraco.Web.UI.Client

Bumps [socket.io-parser](https://github.com/socketio/socket.io-parser) from 4.0.4 to 4.0.5.
- [Release notes](https://github.com/socketio/socket.io-parser/releases)
- [Changelog](https://github.com/socketio/socket.io-parser/blob/main/CHANGELOG.md)
- [Commits](https://github.com/socketio/socket.io-parser/compare/4.0.4...4.0.5)

---
updated-dependencies:
- dependency-name: socket.io-parser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* update block grid panel name (#13325)

Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com>

* Bump async from 2.6.3 to 2.6.4 in /src/Umbraco.Web.UI.Client

Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4.
- [Release notes](https://github.com/caolan/async/releases)
- [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md)
- [Commits](https://github.com/caolan/async/compare/v2.6.3...v2.6.4)

---
updated-dependencies:
- dependency-name: async
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump eventsource from 1.1.0 to 1.1.2 in /src/Umbraco.Web.UI.Client

Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.1.0 to 1.1.2.
- [Release notes](https://github.com/EventSource/eventsource/releases)
- [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md)
- [Commits](https://github.com/EventSource/eventsource/compare/v1.1.0...v1.1.2)

---
updated-dependencies:
- dependency-name: eventsource
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump minimist from 1.2.5 to 1.2.7 in /src/Umbraco.Web.UI.Client

Bumps [minimist](https://github.com/minimistjs/minimist) from 1.2.5 to 1.2.7.
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.7)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Management API: SearchController improvements (#13420)

* remove typo of double PagedViewModel in response

* add providerProperties with custom formatter

* use a more descriptive variable name

* use a more descriptive variable name for property types

* generate new schema

Co-authored-by: Zeegaan <nge@umbraco.dk>

* Bump minimatch from 3.0.4 to 3.1.2 in /src/Umbraco.Web.UI.Client

Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Zeegaan <nge@umbraco.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Ronald Barendse <ronald@barend.se>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Blake Watt <bkclerke@users.noreply.github.com>
Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com>
2022-11-18 09:00:43 +01:00

81 lines
3.0 KiB
C#

using Examine;
using Examine.Search;
using Lucene.Net.QueryParsers.Classic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.ManagementApi.Services;
using Umbraco.Cms.ManagementApi.ViewModels.Pagination;
using Umbraco.Cms.ManagementApi.ViewModels.Search;
using Umbraco.Extensions;
namespace Umbraco.Cms.ManagementApi.Controllers.Search;
[ApiVersion("1.0")]
public class SearcherSearchSearchController : SearchControllerBase
{
private readonly IExamineManagerService _examineManagerService;
public SearcherSearchSearchController(IExamineManagerService examineManagerService) => _examineManagerService = examineManagerService;
[HttpGet("searcher/{searcherName}/search")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<SearchResultViewModel>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<ActionResult<PagedViewModel<SearchResultViewModel>>> GetSearchResults(string searcherName, string? query, int skip, int take)
{
query = query?.Trim();
if (query.IsNullOrWhiteSpace())
{
return new PagedViewModel<SearchResultViewModel>();
}
if (!_examineManagerService.TryFindSearcher(searcherName, out ISearcher searcher))
{
var invalidModelProblem = new ProblemDetails
{
Title = "Could not find a valid searcher",
Detail = "The provided searcher name did not match any of our registered searchers",
Status = StatusCodes.Status404NotFound,
Type = "Error",
};
return NotFound(invalidModelProblem);
}
ISearchResults results;
// NativeQuery will work for a single word/phrase too (but depends on the implementation) the lucene one will work.
try
{
results = searcher
.CreateQuery()
.NativeQuery(query)
.Execute(QueryOptions.SkipTake(skip, take));
}
catch (ParseException)
{
var invalidModelProblem = new ProblemDetails
{
Title = "Could not parse the query",
Detail = "Parser could not parse the query. Please double check if the query is valid. Sometimes this can also happen if your query starts with a wildcard (*)",
Status = StatusCodes.Status404NotFound,
Type = "Error",
};
return BadRequest(invalidModelProblem);
}
return await Task.FromResult(new PagedViewModel<SearchResultViewModel>
{
Total = results.TotalItemCount,
Items = results.Select(x => new SearchResultViewModel
{
Id = x.Id,
Score = x.Score,
Fields = x.AllValues.OrderBy(y => y.Key).Select(y => new FieldViewModel { Name = y.Key, Values = y.Value }),
}),
});
}
}