Klororf.AzSearchLinq
0.7.0
dotnet add package Klororf.AzSearchLinq --version 0.7.0
NuGet\Install-Package Klororf.AzSearchLinq -Version 0.7.0
<PackageReference Include="Klororf.AzSearchLinq" Version="0.7.0" />
paket add Klororf.AzSearchLinq --version 0.7.0
#r "nuget: Klororf.AzSearchLinq, 0.7.0"
// Install Klororf.AzSearchLinq as a Cake Addin
#addin nuget:?package=Klororf.AzSearchLinq&version=0.7.0
// Install Klororf.AzSearchLinq as a Cake Tool
#tool nuget:?package=Klororf.AzSearchLinq&version=0.7.0
AzSearchLinq: Simplify Your Queries to Azure Cognitive Search
AzSearchLinq
is a .NET library that streamlines queries to Azure Cognitive Search. It allows developers to create more readable code when consume azure search
Table of Contents
- Introduction
- Fluent Mode
- Limits
Introduction
AzSearchLinq
is a tool that makes querying Azure Cognitive Search easier. With its "Fluent" mode, you can construct OData queries in a more readable and efficient way.
Fluent Mode
In Fluent mode, you can create queries like this:
var test = _searchClient.Fluent<Product>()
.Equal(x => x.Description, "A")
.Greater(x => x.Price, 2);
var test2 = _searchClient.Fluent<Product>()
.Equal(x => x.Size, "M")
.LessOrEqual(x => x.Price, 100);
var test3 = _searchClient.Fluent<Product>()
.Parentheses(fluent =>fluent
.Equal(x => x.Description, "A")
.Equal(x => x.Price, 2)
.Parentheses(x =>
x.Equal(x => x.Size, "M")
)
);
You can also specify the logical operator (AND or OR) between conditions:
_searchClient.Fluent<Product>()
.Equal(x => x.Size, "2")
.LessOrEqual(x => x.Price, 2, LogicalOperator.Or);
Additionally, you can use the conditional parameter to ignore parts of the query based on values:
var x = 1 == 2;
_searchClient.Fluent<Product>()
.Equal(x => x.Size, "2")
.LessOrEqual(x => x.Price, 2, LogicalOperator.Or, x);
Limits
At this moment you can only use lambda operators, coditionals,search.ismatch(), search.in() in fluent mode for other things you can use the Linqeable way
Linqueable
Where
- Filter with conditional operators (==,!=...)
- Filter with string operatos (StartsWith,EndsWith,Contains)
- use search.in method
- filter with lambdas for complex types
Select
- Get the results and transform to other types
examples
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.Where<Product>(x =>x.ProductName != "Mr").Select(x=>x.Product);
Also you can concatenate multiple where
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.Where<Product>(x =>x.ProductName != "Mr")
.And(x=>x.Price == 20)
.Search();
/// produces ProductName ne 'Mr' and Price eq 20
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.Where<Product>(x =>x.ProductName != "Mr")
.Or(x=>x.Price == 20)
.Search();
/// produces ProductName ne 'Mr' or Price eq 20
Use logical operators
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.Where<Product>(x =>x.ProductName != "Mr" && x.Price >10)
.And(x=>x.Price == 20)
.Search();
Use string methods for search
/// is highly recomended set a custom analyzer for search
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.Where<Product>(x =>x.Description.StartsWith("Blu"))
.Search();
/// Produces search.ismatch('Blu*','Description')
Filter by the properties values
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
var res = srchclient.SubWhere<Product,Color>(x =>x.Colors,x=>x.Hex="anything")
.Search();
/// Produces Colors/any(x: x/Hex eq 'anything')
Product | Versions 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. |
-
net8.0
- Azure.Search.Documents (>= 11.5.1)
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 |
---|---|---|
0.7.0 | 72 | 5/21/2024 |
0.6.1 | 79 | 5/20/2024 |
0.6.0 | 79 | 5/10/2024 |
0.5.0-prerelease | 66 | 5/10/2024 |
0.4.0-alpha | 81 | 5/7/2024 |
0.3.0-alpha | 77 | 4/30/2024 |
0.2.1-alpha | 79 | 4/25/2024 |
0.2.0.3-alpha | 81 | 4/16/2024 |
0.2.0.2-alpha | 87 | 4/14/2024 |
0.2.0.1-alpha | 75 | 4/12/2024 |
0.1.1-alpha | 69 | 3/29/2024 |
0.1.0-alpha | 72 | 3/27/2024 |