I was looking at how to perform full-text searching and indexing similar to Whoosh in python.
I have looked at Lucene.NET but it looks like it's not compatible with ASP.NET Core (2.0 or higher).
Are there any other alternatives for a full-text search engine in this tech stack?
Entity Framework Core 2.1.0 introduced Full Text Search Compatibility using FreeText
and EF Core 2.2.0 introduced Contains
.
EF and LINQ using Contains
:
string criteria = "Find This";
var items = Inventory.Where(x => EF.Functions.Contains(x.KeySearchField, criteria)).ToList();
You can use this nuget package Bsa.Search.Core.
This package compatible with .Net Core 3.1 and has no dependencies.
The library contains 3 index types:
Example of using Memory index
var field = "*"; // search in any field
var query = "(first & \"second and four*\") | (four* ~3 \'six\')"; //search word: first and phrase with wildcard or four- wildcard on distance 3 with six
var documentIndex = new MemoryDocumentIndex();// instance of new memory index
var content = "six first second four"; // text that is indexed
var searchService = new SearchServiceEngine(documentIndex);//service engine for working with indexes
var doc = new IndexDocument("ExternalId");//the document to be indexed and externalId
doc.Add("content".GetField(content)); // adding a new field: content
searchService.Index(new IndexDocument[]
{
doc// saving the document to the index
});
var parsed = query.Parse(field); // parsing the text and making a Boolean query
var request = new SearchQueryRequest() //
{
Query = parsed,
Field = field,
};
var result = searchService.Search(request); //
Result will be
You can use this nuget package Bsa.Search.Core but under .net core 3.1 or .net framework 472
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With