我是lucene.net的新手.我想在客户端数据库上实现搜索功能.我有以下场景:
为了优化搜索结果,我们需要在区域(多个),Pincode等上提供过滤器.换句话说,我需要对以下sql查询进行等效的lucene查询:
SELECT * FROM CLIENTS
WHERE CITY = N'City1'
AND (Area like N'%area1%' OR Area like N'%area2%')
Run Code Online (Sandbox Code Playgroud)
SELECT * FROM CILENTS
WHERE CITY IN ('MUMBAI', 'DELHI')
AND CLIENTTYPE IN ('GOLD', 'SILVER')
Run Code Online (Sandbox Code Playgroud)下面是我实现的用于提供城市搜索作为过滤器的代码:
private static IEnumerable<ClientSearchIndexItemDto> _search(string searchQuery, string city, string searchField = "")
{
// validation
if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", "")))
return new List<ClientSearchIndexItemDto>();
// set up Lucene searcher
using (var searcher = new IndexSearcher(_directory, false))
{
var hits_limit = 1000;
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
// search …Run Code Online (Sandbox Code Playgroud) lucene.net ×1