开发者

Solr Date Format issue in the Query

I am trying to implement the solr query using .NET but i am getting bad request when i try to connect to the solr for search since my dat开发者_运维知识库e format is wrong.Can any one tell me the exact syntax to create a date format in .net

Created_Dt :[12/12/2008 3:45 PM TO *]


SolrNet already does the conversion to Solr time format for you, you only need to work with the standard DateTime type:

new SolrQueryByRange<DateTime?>("Created_Dt", new DateTime(2008, 12, 12, 15, 45, 0), null);


You need to search based on a UTC timestmap. Here is some example .NET code to generate it:

DateTime dt = DateTime.Now.ToUniversalTime();
System.Diagnostics.Debug.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));

And a query using your example field that would use that format:

Created_Dt:[2011-06-07T13:35:47Z TO NOW]

Also, make sure you convert your dates to UTC format before you store them.


I could get the solr date format using the code below,

DateTimeFieldSerializer date = new DateTimeFieldSerializer();

string fromDt = date.SerializeDate(searchCriteria.From);

string toDt = date.SerializeDate(searchCriteria.To);

This works fine and I can search using the date range now..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜