我正在研究如何执行类似于python中的Whoosh的全文本搜索和索引。
我看过Lucene.NET,但它似乎与ASP.NET Core(2.0或更高版本)不兼容。
在此技术堆栈中,全文搜索引擎是否还有其他选择?
答案 0 :(得分:3)
Entity Framework Core 2.1.0引入了使用FreeText
的全文本搜索兼容性,而EF Core 2.2.0引入了Contains
。
使用Contains
的EF和LINQ:
string criteria = "Find This";
var items = Inventory.Where(x => EF.Functions.Contains(x.KeySearchField, criteria)).ToList();
答案 1 :(得分:0)
您可以使用此nuget包Bsa.Search.Core。
此软件包与.Net Core 3.1兼容,并且没有依赖性。
该库包含3种索引类型:
使用内存索引的示例
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); //
您可以使用此nuget包Bsa.Search.Core,但在.net core 3.1或.net framework 472下