Skip to content

Commit 7d05140

Browse files
committed
merge: SquidStd.Search.Abstractions + SquidStd.Search.Elasticsearch (indexing + LINQ query)
2 parents e68a595 + f230986 commit 7d05140

28 files changed

Lines changed: 1288 additions & 0 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ block until cancellation for long-running hosts.
9191
| `SquidStd.Workers` | Worker runtime: consume jobs, dispatch to `IJobHandler`s, publish heartbeats (`AddWorkers`). | [![readme](https://img.shields.io/badge/readme-1390A3.svg)](src/SquidStd.Workers/README.md) · [![NuGet](https://img.shields.io/nuget/v/SquidStd.Workers.svg)](https://www.nuget.org/packages/SquidStd.Workers/) |
9292
| `SquidStd.Workers.Manager` | Job enqueue, heartbeat registry, offline sweep, opt-in ASP.NET endpoints (`AddWorkerManager`). | [![readme](https://img.shields.io/badge/readme-1390A3.svg)](src/SquidStd.Workers.Manager/README.md) · [![NuGet](https://img.shields.io/nuget/v/SquidStd.Workers.Manager.svg)](https://www.nuget.org/packages/SquidStd.Workers.Manager/) |
9393
| `SquidStd.Templates` | `dotnet new` templates for scaffolding SquidStd projects (host, ASP.NET, worker, manager). | [![readme](https://img.shields.io/badge/readme-1390A3.svg)](src/SquidStd.Templates/README.md) · [![NuGet](https://img.shields.io/nuget/v/SquidStd.Templates.svg)](https://www.nuget.org/packages/SquidStd.Templates/) |
94+
| `SquidStd.Search.Abstractions` | Search/indexing contracts (`IIndexableEntity`, `[SearchIndex]`, `ISearchService`). | [![readme](https://img.shields.io/badge/readme-1390A3.svg)](src/SquidStd.Search.Abstractions/README.md) · [![NuGet](https://img.shields.io/nuget/v/SquidStd.Search.Abstractions.svg)](https://www.nuget.org/packages/SquidStd.Search.Abstractions/) |
95+
| `SquidStd.Search.Elasticsearch` | Elasticsearch indexing + constrained LINQ query provider (`AddElasticsearch`). | [![readme](https://img.shields.io/badge/readme-1390A3.svg)](src/SquidStd.Search.Elasticsearch/README.md) · [![NuGet](https://img.shields.io/nuget/v/SquidStd.Search.Elasticsearch.svg)](https://www.nuget.org/packages/SquidStd.Search.Elasticsearch/) |
9496

9597
## Architecture
9698

SquidStd.slnx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<Project Path="src/SquidStd.Workers/SquidStd.Workers.csproj" />
2424
<Project Path="src/SquidStd.Workers.Manager/SquidStd.Workers.Manager.csproj" />
2525
<Project Path="src/SquidStd.Templates/SquidStd.Templates.csproj" />
26+
<Project Path="src/SquidStd.Search.Abstractions/SquidStd.Search.Abstractions.csproj" />
27+
<Project Path="src/SquidStd.Search.Elasticsearch/SquidStd.Search.Elasticsearch.csproj" />
2628
</Folder>
2729
<Folder Name="/tests/">
2830
<Project Path="tests/SquidStd.Tests/SquidStd.Tests.csproj" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[!include[](../../src/SquidStd.Search.Abstractions/README.md)]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[!include[](../../src/SquidStd.Search.Elasticsearch/README.md)]

docs/articles/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
href: workers-manager.md
4747
- name: SquidStd.Templates
4848
href: templates.md
49+
- name: SquidStd.Search.Abstractions
50+
href: search-abstractions.md
51+
- name: SquidStd.Search.Elasticsearch
52+
href: search-elasticsearch.md
4953
- name: Serialization
5054
href: serialization.md
5155
- name: Scheduler
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace SquidStd.Search.Abstractions.Attributes;
2+
3+
/// <summary>
4+
/// Declares the Elasticsearch index for a type. The name supports environment-variable expansion:
5+
/// <c>${VAR}</c> and <c>${VAR:-default}</c> (e.g. <c>"orders_${ENV:-dev}"</c>).
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
8+
public sealed class SearchIndexAttribute : Attribute
9+
{
10+
/// <summary>The index name (template).</summary>
11+
public string Name { get; }
12+
13+
/// <summary>Initializes the attribute with the index name template.</summary>
14+
public SearchIndexAttribute(string name)
15+
{
16+
Name = name;
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace SquidStd.Search.Abstractions.Exceptions;
2+
3+
/// <summary>Thrown when Elasticsearch returns a non-successful response.</summary>
4+
public sealed class SearchException : Exception
5+
{
6+
/// <summary>Initializes the exception with a message.</summary>
7+
public SearchException(string message)
8+
: base(message)
9+
{
10+
}
11+
12+
/// <summary>Initializes the exception with a message and inner exception.</summary>
13+
public SearchException(string message, Exception innerException)
14+
: base(message, innerException)
15+
{
16+
}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SquidStd.Search.Abstractions.Interfaces;
2+
3+
/// <summary>
4+
/// Marks an entity as indexable and supplies its document id. The target index comes from a
5+
/// <see cref="Attributes.SearchIndexAttribute" /> on the type (or the lowercased type name).
6+
/// </summary>
7+
public interface IIndexableEntity
8+
{
9+
/// <summary>Stable document id within the index.</summary>
10+
string IndexId { get; }
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace SquidStd.Search.Abstractions.Interfaces;
2+
3+
/// <summary>
4+
/// Indexes, deletes, and queries <see cref="IIndexableEntity" /> documents.
5+
/// </summary>
6+
public interface ISearchService
7+
{
8+
/// <summary>Indexes (creates or replaces) a single document.</summary>
9+
Task IndexAsync<T>(T entity, bool refresh = false, CancellationToken cancellationToken = default) where T : IIndexableEntity;
10+
11+
/// <summary>Indexes many documents in one bulk request.</summary>
12+
Task IndexManyAsync<T>(IEnumerable<T> entities, bool refresh = false, CancellationToken cancellationToken = default) where T : IIndexableEntity;
13+
14+
/// <summary>Deletes a document by id. Returns <c>false</c> when it did not exist.</summary>
15+
Task<bool> DeleteAsync<T>(string indexId, bool refresh = false, CancellationToken cancellationToken = default) where T : IIndexableEntity;
16+
17+
/// <summary>Creates the index for <typeparamref name="T" /> if it does not exist (dynamic mapping). Idempotent.</summary>
18+
Task EnsureIndexAsync<T>(CancellationToken cancellationToken = default) where T : IIndexableEntity;
19+
20+
/// <summary>Returns a constrained <see cref="IQueryable{T}" /> translated to the Elasticsearch query DSL.</summary>
21+
IQueryable<T> Query<T>() where T : IIndexableEntity;
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<p align="center">
2+
<img src="https://raw.githubusercontent.com/tgiachi/squid-std/main/assets/icon.png" alt="SquidStd" width="120" height="120" />
3+
</p>
4+
5+
<h1 align="center">SquidStd.Search.Abstractions</h1>
6+
7+
<p align="center">
8+
<a href="https://www.nuget.org/packages/SquidStd.Search.Abstractions/"><img src="https://img.shields.io/nuget/v/SquidStd.Search.Abstractions.svg" alt="NuGet" /></a>
9+
<img src="https://img.shields.io/nuget/dt/SquidStd.Search.Abstractions.svg" alt="Downloads" />
10+
<a href="https://tgiachi.github.io/squid-std/articles/search-abstractions.html"><img src="https://img.shields.io/badge/docs-DocFX-1390A3.svg" alt="docs" /></a>
11+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" />
12+
</p>
13+
14+
Search/indexing contracts for SquidStd: tag entities with `IIndexableEntity` + `[SearchIndex]` (with
15+
`${VAR}` / `${VAR:-default}` environment expansion) and query them via `ISearchService`.
16+
17+
## Install
18+
19+
```bash
20+
dotnet add package SquidStd.Search.Abstractions
21+
```
22+
23+
## Key types
24+
25+
| Type | Purpose |
26+
|------|---------|
27+
| `IIndexableEntity` | Marks an entity indexable and supplies its `IndexId`. |
28+
| `SearchIndexAttribute` | Declares the index name (env-expanded). |
29+
| `ISearchService` | Index / delete / ensure-index / `Query<T>()`. |
30+
| `SearchIndexNameResolver` | Resolves the index name from the attribute/type + environment. |
31+
32+
## License
33+
34+
MIT — part of [SquidStd](https://github.com/tgiachi/squid-std).

0 commit comments

Comments
 (0)