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.
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.
FirstName: John AND DOB: 5/12/1998
. For the ID I'm afraid Lucene doesn't support that type of operation. You can always fetch the records and filter them again... – rae1DOB: 5/12/1998
. You can useBooleanQuery
to specify the two queries. – rae1