Lucene搜索的过滤结果 [英] Filtering results of Lucene search
问题描述
让我解释一下我的问题.我正在使用Lucene在asp.net网页中搜索并显示结果.当我搜索时,Lucene会显示与我的搜索相关的所有记录.例如,我有5000条名称为John的记录.如果我输入John,它将显示所有这5000条记录.我想基于其他一些属性来限制这5000条记录.我有四个属性,分别是名字,姓氏,DOB和ID.在这5000条记录中,我希望它仅显示用户输入的DOB记录.这意味着只显示1998年5月12日拥有DOB的john的记录.这样会将结果限制在50条左右.完成此操作后,我想搜索具有相同ID的所有字段,然后显示这些记录.最后,我将获得具有给定DOB和相同ID的John记录.
Let me explain my problem. I am using Lucene to search and display the results in asp.net web page. When I am searching, the Lucene is displaying all the records associated with my search. For Example I have 5000 records with name John. If I type John it is displaying all this 5000 records. I want to restrict this 5000 records based on some other attribute. I have four attributes namely First Name, Last Name, DOB and ID. Out those 5000 records I want it to display only the ones with the inputted DOB by the user. This means just display the records of john who have DOB as 5/12/1998. This will restrict the result to around 50 records. Once I am done with that I want to search all the fields who have same ID and then display those records. In the end I will have records of John with given DOB and same ID.
注意:通过DOB进行过滤是出于安全目的.
Note: Filtering by DOB is for security purpose.
以下是我的搜索代码.
The following is my Code for search.
List<SearchResults> Searchresults = new List<SearchResults>();
string indexFileLocation = @"C:\o";
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation);
string[] searchfields = new string[] { "fname", "lname", "dob", "id"};
IndexSearcher indexSearcher = new IndexSearcher(dir);
var hits = indexSearcher.Search(QueryMaker(searchString, searchfields));
for (int i = 0; i < hits.Length(); i++)
{
SearchResults result = new SearchResults();
result.fname = hits.Doc(i).GetField("fname").StringValue();
result.lname = hits.Doc(i).GetField("lname").StringValue();
result.dob = hits.Doc(i).GetField("dob").StringValue();
result.id = hits.Doc(i).GetField("id").StringValue();
Searchresults.Add(result);
}
如果您有任何疑问,请告诉我.
Please let me know if you have any questions.
推荐答案
我讨厌这样做.但是我找到了答案.
I hate to do this. But I found the answer.
它
Filter fil= new QueryWrapperFilter(new TermQuery( new Term(field, "5/12/1998")));
var hits = indexSearcher.Search(QueryMaker(searchString, searchfields), fil);
您可以使用以上代码过滤结果.
You can filter the results with the above code.
我认为过滤查找值后可能无法返回.有人不同意吗?
I don't think its possible to go back after filtering for looking values. Anybody disagree?
这篇关于Lucene搜索的过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!