Sun.Core.OpenSearch 1.0.0

dotnet add package Sun.Core.OpenSearch --version 1.0.0                
NuGet\Install-Package Sun.Core.OpenSearch -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sun.Core.OpenSearch" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sun.Core.OpenSearch --version 1.0.0                
#r "nuget: Sun.Core.OpenSearch, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sun.Core.OpenSearch as a Cake Addin
#addin nuget:?package=Sun.Core.OpenSearch&version=1.0.0

// Install Sun.Core.OpenSearch as a Cake Tool
#tool nuget:?package=Sun.Core.OpenSearch&version=1.0.0                

Cách dùng OpenSearch trong Startup.cs hoặc nơi bạn cấu hình services: services.AddOpenSearch(Configuration);


cách dùng ở controller hoặc api

using Sun.Core.OpenSearch.Helpers; using Sun.Core.OpenSearch.Services; using Sun.Core.OpenSearch.Models;

public class YourController : ControllerBase { private readonly IOpenSearchService _openSearchService;

public YourController(IOpenSearchService openSearchService)
{
    _openSearchService = openSearchService;
}

[HttpGet("search")]
public async Task<IActionResult> Search(string query)
{
    var searchResponse = await _openSearchService.SearchAsync<YourDocumentType>(
        OpenSearchHelpers.BuildMatchQuery<YourDocumentType>("title", query),
        "your_index_name"
    );

    return Ok(searchResponse.Documents);
}

[HttpGet("advanced-search")]
public async Task<IActionResult> AdvancedSearch(string query, double? minPrice, double? maxPrice)
{
    var mustClauses = new List<Func<QueryContainerDescriptor<YourDocumentType>, QueryContainer>>
    {
        q => q.Match(m => m.Field(f => f.Title).Query(query))
    };

    if (minPrice.HasValue || maxPrice.HasValue)
    {
        mustClauses.Add(q => q.Range(r => r
            .Field(f => f.Price)
            .GreaterThanOrEquals(minPrice)
            .LessThanOrEquals(maxPrice)
        ));
    }

    var searchResponse = await _openSearchService.SearchAsync<YourDocumentType>(
        OpenSearchHelpers.BuildBoolQuery<YourDocumentType>(mustClauses, new List<Func<QueryContainerDescriptor<YourDocumentType>, QueryContainer>>(), new List<Func<QueryContainerDescriptor<YourDocumentType>, QueryContainer>>()),
        "your_index_name"
    );

    return Ok(searchResponse.Documents);
}

}

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 90 7/25/2024