我正在研究如何执行全文搜索和索引,类似于python中的Whoosh。
我看过Lucene.NET,但它看起来与ASP.NET Core (2.0或更高版本)不兼容。
在这个技术栈中,对于全文搜索引擎还有其他选择吗?
发布于 2018-11-17 22:50:33
EntityFrameworkCore2.1.0使用FreeText引入全文搜索兼容性,EFCore2.2.0引入了Contains。
使用Contains的EF和LINQ
string criteria = "Find This";
var items = Inventory.Where(x => EF.Functions.Contains(x.KeySearchField, criteria)).ToList();发布于 2020-09-03 20:10:10
您可以使用这个nuget包Bsa.Search.Core。
此包与.Net Core3.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核心3.1或.net框架472下
https://stackoverflow.com/questions/53342585
复制相似问题