简体   繁体   English

过滤Lucene搜索结果

[英]Filtering results of Lucene search

Let me explain my problem. 让我解释一下我的问题。 I am using Lucene to search and display the results in asp.net web page. 我正在使用Lucene在asp.net网页中搜索并显示结果。 When I am searching, the Lucene is displaying all the records associated with my search. 当我搜索时,Lucene显示与我的搜索相关的所有记录。 For Example I have 5000 records with name John. 例如,我有5000条名为John的记录。 If I type John it is displaying all this 5000 records. 如果我键入John,它将显示所有这5000条记录。 I want to restrict this 5000 records based on some other attribute. 我想根据其他一些属性限制这5000条记录。 I have four attributes namely First Name, Last Name, DOB and ID. 我有四个属性,即名字,姓氏,DOB和ID。 Out those 5000 records I want it to display only the ones with the inputted DOB by the user. 在那5000条记录中,我希望它只显示用户输入的DOB。 This means just display the records of john who have DOB as 5/12/1998. 这意味着只显示拥有DOB为5/12/1998的约翰的记录。 This will restrict the result to around 50 records. 这会将结果限制为大约50条记录。 Once I am done with that I want to search all the fields who have same ID and then display those records. 完成后,我想搜索具有相同ID的所有字段,然后显示这些记录。 In the end I will have records of John with given DOB and same ID. 最后,我将使用给定的DOB和相同的ID记录John的记录。

Note: Filtering by DOB is for security purpose. 注意:DOB过滤是出于安全目的。

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. 但我找到了答案。

Its 它的

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? 有人不同意吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM