I understand how Lucene.net can work for text indexing. Will I be able to efficiently search for documents based on a given date range? Or will Lucene.net just use text matching to match the dates?
我理解Lucene.net如何用于文本索引。我能否根据给定的日期范围有效地搜索文档?或者Lucene.net会使用文本匹配来匹配日期吗?
2 个解决方案
#1
6
Lucene.Net will just use text matching, so you'd need to format the dates correctly before adding to the index:
Lucene.Net将只使用文本匹配,因此您需要在添加到索引之前正确格式化日期:
public static string Serialize(DateTime dateTime)
{
return dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
}
public static DateTime Deserialize(string str)
{
return DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
}
You can then, for example, perform a range based query to filter by date (e.g. 2006* to 2007* to include all dates in 2006 and 2007).
例如,您可以执行基于范围的查询以按日期过滤(例如,2006 *至2007 *以包括2006年和2007年的所有日期)。
#2
1
I went in to trouble when i converted date in to yyyymmddHHmmssff
. When i tried sorting the data, it gave me an exception that too big to convert..something. Hence i search and found then you need to have two columns. one in yyyymmdd
and the other HHmmss
, and then use Sort[]
and give these two columns and then use. This will solve the issue.
当我将约会转换为yyyymmddHHmmssff时,我遇到了麻烦。当我尝试对数据进行排序时,它给了我一个例外,它太大而无法转换。因此我搜索并找到你需要有两列。一个在yyyymmdd和另一个HHmmss,然后使用Sort []并给出这两列,然后使用。这将解决问题。
#1
6
Lucene.Net will just use text matching, so you'd need to format the dates correctly before adding to the index:
Lucene.Net将只使用文本匹配,因此您需要在添加到索引之前正确格式化日期:
public static string Serialize(DateTime dateTime)
{
return dateTime.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
}
public static DateTime Deserialize(string str)
{
return DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
}
You can then, for example, perform a range based query to filter by date (e.g. 2006* to 2007* to include all dates in 2006 and 2007).
例如,您可以执行基于范围的查询以按日期过滤(例如,2006 *至2007 *以包括2006年和2007年的所有日期)。
#2
1
I went in to trouble when i converted date in to yyyymmddHHmmssff
. When i tried sorting the data, it gave me an exception that too big to convert..something. Hence i search and found then you need to have two columns. one in yyyymmdd
and the other HHmmss
, and then use Sort[]
and give these two columns and then use. This will solve the issue.
当我将约会转换为yyyymmddHHmmssff时,我遇到了麻烦。当我尝试对数据进行排序时,它给了我一个例外,它太大而无法转换。因此我搜索并找到你需要有两列。一个在yyyymmdd和另一个HHmmss,然后使用Sort []并给出这两列,然后使用。这将解决问题。