mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.9 KiB
54 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Squidex.Areas.Api.Controllers.Search.Models;
|
|
using Squidex.Domain.Apps.Entities.Search;
|
|
using Squidex.Infrastructure.Commands;
|
|
using Squidex.Shared;
|
|
using Squidex.Web;
|
|
|
|
namespace Squidex.Areas.Api.Controllers.Search
|
|
{
|
|
/// <summary>
|
|
/// Retrieves search results.
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = nameof(Search))]
|
|
public class SearchController : ApiController
|
|
{
|
|
private readonly ISearchManager searchManager;
|
|
|
|
public SearchController(ISearchManager searchManager, ICommandBus commandBus)
|
|
: base(commandBus)
|
|
{
|
|
this.searchManager = searchManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get search results.
|
|
/// </summary>
|
|
/// <param name="app">The name of the app.</param>
|
|
/// <param name="query">The search query.</param>
|
|
/// <returns>
|
|
/// 200 => Search results returned.
|
|
/// 404 => App not found.
|
|
/// </returns>
|
|
[HttpGet]
|
|
[Route("apps/{app}/search/")]
|
|
[ProducesResponseType(typeof(SearchResultDto[]), StatusCodes.Status200OK)]
|
|
[ApiPermissionOrAnonymous(Permissions.AppSearch)]
|
|
[ApiCosts(0)]
|
|
public async Task<IActionResult> GetSearchResults(string app, [FromQuery] string? query = null)
|
|
{
|
|
var result = await searchManager.SearchAsync(query, Context, HttpContext.RequestAborted);
|
|
|
|
var response = result.Select(SearchResultDto.FromDomain).ToArray();
|
|
|
|
return Ok(response);
|
|
}
|
|
}
|
|
}
|
|
|