A fast and easy way to implement scalable searching with Linq in .NET. It uses reflection to gather all properties that one wants to search in, and then runs a query using dynamic linq and .Contains("{search}") to return all results which match the searchstring.
If you have any thoughts, improvements, or just want to chat about Linq.Search.Core, go to our Gitter chat and join in on the discussions.
This package is available on nuget, run your available command and it should install nicely.
npm install Linq.Search.Core
Install-Package Linq.Search.Core
dotnet add package Linq.Search.Core
Add the [Searchable]
attribute to any property or related object that you want to be able to index searches by. For example, say that you have some sort of database consisting of Persons
which in turn are connected to Facilities
, then the classes would look something like this:
public class Person
{
[Searchable]
public string Name { get; }
public string Description { get; }
[Searchable]
public Facility Facility { get; }
}
public class Facility
{
[Searchable]
public string Name { get; }
public virtual ICollection<Person> Persons { get; set; }
}
Search for Bruce
public class Testing {
public IQueryable<Person> SearchForBruce()
{
var persons = new List<Person>
{
new Person
{
Name = "Bruce Wayne",
Description = "Batman",
Facility = new Facility
{
Name = "Batcave"
}
}
};
return persons
.AsQueryable()
.SearchFor("Bruce");
}
}
The search-function is also built to support queries with multiple subqueries. For example if one would want to search for any elements matching "Bruce" or "Batcave". To do this, all search queries would need to be separated by "|".
Search for Bruce OR Batcave.
return persons
.AsQueryable()
.SearchFor("Bruce|Batcave");
- Implement .SearchFor() for all types of IEnumerables!
- See if we can cut down dependencies.
- Implement Levehstein-distance to order search-results by significance.
- System.Linq.Dynamic.Core - Dynamic Linq used to run queries.
- Lennart Hammarström - lhammarstrom
This project is licensed under the MIT License - see the LICENSE.md file for details
- Stef Heyenrath - Dynamic Linq - System.Linq.Dynamic.Core
- Yannick Lung - Icon - IconFinder