Usage
Installation
To install this package, search for DealerOn.QueryLanguage in any of the DealerOn nuget feeds. This can be done through the Nuget UI in Visual Studio or the dotnet CLI.
dotnet add package DealerOn.QueryLanguage -S http://nuget.dealeron.us:8624/nuget/Mainline/
Parsing a query can be done simply by calling:
DqlParseResult result = DqlParser.Default.TryParse("make = 'chevy'");
if (result.HasValue)
{
DqlExpression expression = result.Value;
// use expression
}
the Root property represents the root DqlExpression object of the syntax tree.
Creating an Elasticsearch Query
The DealerOn.DQL.Elasticsearch package provides an additional layer to translate the DQL syntax tree into an elasticsearch query that's compatible with NEST:
DqlParseResult result = DqlParser.Default.TryParse(dqlString);
if (!result.HasValue)
{
return;
}
DqlEsSetting settings = DqlEsSettings.Default<Vehicle>();
DqlParseResult variables = DqlVariables.FromObject(new
{
DealerMake = Dealer.Make,
ThisYear = DateTime.Now.Year,
});
DqlQuery query = result.Root.ToElasticQuery<Vehicle>(settings, variables);
var searchResult = ElasticClient.Search<Vehicle>(new SearchRequest
{
Query = query
});
Creating an In-Memory Delegate
The DealerOn.QueryLanguage.Linq package provides a similar layer for translating queries to a compiled LINQ expression. Once compiled, this can be executed at speeds comparable to compiled c# code.
DqlParseResult result = DqlParser.Default.TryParseToExpression<Vehicle>("Make = DealerMake");
DqlVariables variables = DqlVariables.FromObject(new
{
DealerMake = Dealer.Make,
ThisYear = DateTime.Now.Year,
});
bool result = result.Execute(vehicle, variables);