我不知道如何索引和搜索 Registred_Date(它包含 sql 格式的日期时间)。我需要在年或日之间搜索。我使用布尔查询进行搜索。下面的代码用于数字字段和普通字段索引。
IndexWriter indexWriter = new IndexWriter(dir, new StandardAnalyzer(),Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);
DataSet ds = new DataSet();
//ds contains table
if (ds.Tables[0] != null)
{
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
//Create the Document object
Document doc = new Document();
foreach (DataColumn dc in dt.Columns)
{
string check = dc.ToString();
if (check.Equals("Experience"))
{
int n=Convert.ToInt32(dr[dc.ColumnName]);
NumericField numericField = new NumericField(dc.ColumnName, Field.Store.YES, true);
numericField.SetIntValue(n);
doc.Add(numericField);
}
else if(check.Equals("Registred_Date"))
{
}
else
{
doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED));
}
//Populate the document with the column name and value from our query
}
// Write the Document to the catalog
indexWriter.AddDocument(doc);
}
}
}
// Close the writer
indexWriter.Close();