Solr Date Format issue in the Query

倖福魔咒の 提交于 2019-12-08 11:29:24

问题


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 date 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 *]


回答1:


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);



回答2:


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.




回答3:


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..



来源:https://stackoverflow.com/questions/6265247/solr-date-format-issue-in-the-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!