I am building an application that searches a database using Lucene.net.The user decides the fields of the table that want to search on.Now here's the question.How do i implement the multiqueryparser so that it can dynamicly search the specific field that the user has selected.
Here's what i've done if i knew the fields :
document.Add(new Field("FullText",
string.Format("{0} {1} {2} {3}", row["firstName"], row["LastName"], row["Job"], row["ID"]), Field.Store.YES, Field.Index.ANALYZED));
Which is the string.format
syntax so that i can search the fields that user has selected?If the user selected FirstName and LastName only how to i change the string.format
so i can dynamicly search for the two specific fields?
My try:
for (int i = 0; i < Variables.selectedfieldsname.Count() ; i++)
{
document.Add(new Field(Variables.selectedfieldsname[i], row[Variables.selectedfieldsname[i]].ToString(), Field.Store.YES, Field.Index.ANALYZED));
fieldNum += "{" + i + "} ";
fields += row[Variables.selectedfieldsname[i]].ToString() + " ";
}
document.Add(new Field("FullText", string.Format(fieldNum, fields), Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(document);