Bsa.Search.Core.Rest 10.0.10

dotnet add package Bsa.Search.Core.Rest --version 10.0.10
                    
NuGet\Install-Package Bsa.Search.Core.Rest -Version 10.0.10
                    
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="Bsa.Search.Core.Rest" Version="10.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bsa.Search.Core.Rest" Version="10.0.10" />
                    
Directory.Packages.props
<PackageReference Include="Bsa.Search.Core.Rest" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bsa.Search.Core.Rest --version 10.0.10
                    
#r "nuget: Bsa.Search.Core.Rest, 10.0.10"
                    
#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.
#:package Bsa.Search.Core.Rest@10.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bsa.Search.Core.Rest&version=10.0.10
                    
Install as a Cake Addin
#tool nuget:?package=Bsa.Search.Core.Rest&version=10.0.10
                    
Install as a Cake Tool

Bsa.Search.Core.Rest

A lightweight .NET client for the Bsa.Search REST API host. It wraps the HTTP endpoints of the search server (/api/v1/search/*) in a strongly‑typed C# service, so you can create indexes, index documents and run full‑text queries without dealing with HTTP, routes or JSON by hand.

  • Target framework: .NET 9.0
  • Package version: 9.0.8
  • License: BSD‑2‑Clause
  • Project site: https://bsasearch.org/

Requires a running Bsa.Search API host (version 2.0.22 or newer). The host can be downloaded from https://bsasearch.org/ or installed from the deb/rpm packages.

Installation

Add a reference to the Bsa.Search.Core.Rest package (or the project) to your application. The client pulls in Service.Registry as its only dependency.

<PackageReference Include="Bsa.Search.Core.Rest" Version="9.0.8" />

Quick start

using Bsa.Search.Core.Rest;
using Bsa.Search.Core.Rest.Entities;

ISearchService service = new SearchService("http://localhost:2664");

var index = "test_index";

// create the index if it does not exist yet
if (!service.IsExists(index))
    service.CreateIndex(index);

// wait until all shards are ready
while (!service.IsReady(index))
    Thread.Sleep(100);

// index a document
service.Indexing(new IndexingDocumentBulkRequest
{
    IndexName = index,
    Items = new List<IndexDocumentData>
    {
        new IndexDocumentData
        {
            Id = "doc-1",
            Overwrite = true,
            Fields = new List<IndexFieldData>
            {
                new IndexFieldData("content", "one two nine")
            }
        }
    }
});

// search
var result = service.Search(new SearchDocumentRequest
{
    IndexName = index,
    Field = "*",
    Query = "one & two",
    Count = 100
});

if (result.Hits.Length == 0)
    Console.WriteLine("Nothing found");
else
    foreach (var hit in result.Hits)
        Console.WriteLine($"{hit.Id}: {hit.GetField("content")} (score {hit.Score})");

Creating the client

SearchService implements ISearchService and offers several constructors:

// base address of the API host
new SearchService("http://localhost:2664");

// from settings (ISearchServiceSettings.ApiUrl)
new SearchService(mySettings);

// with a custom HTTP layer (ICallWebApiService) or RestClientResponseSettings
new SearchService(restSettings, myCallWebApiService);

ICallWebApiService can be supplied to control the underlying HTTP calls (timeouts, handlers, service discovery via Service.Registry). When omitted, a default implementation is used.

Operations

Index lifecycle

Method Description
CreateIndex(name) Create an index if it does not exist.
IsExists(name) Whether the index exists.
IsReady(name) Whether the index is ready for indexing/search (all shards ready).
GetState(name) State of the index, one IndexRepositoryInfo per shard.
GetInfo() Information about all indexes on the host.
DropIndex(name) Delete the index with all its data.
DropAndCreateIndex(name) Drop the index and recreate an empty one with the same name.
Flush(name) Flush the index data to disk.
Close(name) Close the index and free its memory (reloaded on next request).
Reindex(name) Rebuild the index.
Clear() Release RAM on the host.
GetVersion() API host version.

Indexing

// bulk
service.Indexing(new IndexingDocumentBulkRequest { IndexName = index, Items = items });

// single document (sent as a bulk request with "title" and "content" fields)
service.Indexing(new SingleDocumentRequest { /* ... */ });

// delete
service.DeleteDocument(new DeleteDocumentRequest { /* ... */ });

Each IndexDocumentData has an external Id, a list of IndexFieldData (Name/Value), optional PublishTime/Timestamp, and an Overwrite flag.

Searching

// full request (POST) — filters, sorting, paging, time ranges
service.Search(new SearchDocumentRequest
{
    IndexName = index,
    Field = "*",                 // field to search in, "*" = all fields
    Query = "one & two",         // Bsa.Search query language
    Count = 100,
    Offset = 0,
    Fields = new List<string> { "content" },  // fields to return
    Order = SortOrderFields.Relevance,
    Direction = SortDirection.Desc,
    Filters = null,
    IsShort = false
});

// convenience GET overloads
service.Search(index, "one & two", field: "*", count: 100);
service.ShortSearch(index, "one & two");   // reduced result set (/short)

IndexSearchResult contains TotalHits, ScoreDocs, ReadyIndexes, IsReady and a Hits array. Each IndexSearchResultHits exposes Id, Score, Timestamp, Published, Terms, a Fields dictionary and a GetField(name) helper.

Documents by id

service.GetByIds(new GetDocumentRequest { IndexName = index, Ids = ids });
var existing = service.GetExistingIds(index, ids);   // which ids are present

Query parsing

string tree = service.ParseQuery("one & two");  // parsed query tree as JSON

Error handling

  • IndexIsNotReadyException is thrown when an operation targets an index whose shards are not ready yet. Poll IsReady(name) before indexing or searching, or handle the exception and retry.
  • While an index of the previous format is being converted to the segment format, the host reports the state Converting (with a Progress percentage in IndexRepositoryInfo); searches return IsReady = false until it finishes.

Notes

  • LinkDocument(...) is obsolete — the API host has no endpoint for it and the call returns 404.
  • Some methods are defined as default interface members and require a reasonably recent API host; SearchService implements them against the current routes.
  • The query syntax (operators &, |, !, phrases, wildcards, etc.) is documented on the project site: https://bsasearch.org/docs/query-language.html

License

BSD‑2‑Clause © Stanislav Batyrgareev

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
10.0.10 117 10/25/2026
9.0.10 104 10/25/2026
9.0.9 104 10/25/2026
9.0.8 111 10/15/2026
9.0.7 256 7/18/2025
8.0.10 101 10/25/2026
8.0.8 108 10/15/2026
8.0.7 222 7/18/2025
7.0.8 115 10/15/2026
7.0.6 407 12/11/2023
7.0.5 279 9/15/2023
6.0.10 119 10/25/2026
6.0.8 132 10/15/2026
6.0.7 1,656 7/16/2024
6.0.6 293 12/11/2023
6.0.5 249 9/15/2023
3.1.14 1,117 12/13/2023
3.1.13 293 12/11/2023
3.1.12 255 9/15/2023
3.1.11 238 9/15/2023
Loading failed

//Api version 2.0.22 or higher
// https://bsasearch.org/Bsa.Search.2.0.22.zip
var service = new SearchService("http://localhost:2664");
 var name = "test_index";

 if (!service.IsExists(name))
 {
  Console.WriteLine("Index does not exists");
  service.CreateIndex(name);
 }

 while (!service.IsReady(name))
 {
  Thread.Sleep(100);
 }

 var externalid = "ExternalId";
 var indexDocumentDatas = new List<IndexDocumentData>()
 {
  new IndexDocumentData()
  {
   Id = externalid,
   Overwrite = true,
   Fields = new List<IndexFieldData>()
  {
   new IndexFieldData(){Value = "one two nine", Name = "content"}
  }}
 };
 service.Indexing(new IndexingDocumentBulkRequest()
 {
  IndexName = name,
  Items = indexDocumentDatas,
 });
 var result = service.Search(new SearchDocumentRequest()
 {
  Field = "*",
  Count = 100000,
  IndexName = name,
  IsShort = false,
  Query = "one & two",

 });
 if (result.Hits.Length == 0)
  Console.WriteLine("Data not found");