Solrnet date conversion issue - solrnet

We are using SolrNet API to Index and Search a set of documents which contains three date fields: Date1, Date2, Date3. The C# class has the following definitions for the three fields
public DateTime? Date1{ get; set; }
public DateTime? Date2{ get; set; }
public DateTime? Date3{ get; set; }
The Solr schema definition is as follows:
<field name="Date1" type="date" indexed="false" stored="true" required="false"/>
<field name="Date2" type="date" indexed="false" stored="true" required="false"/>
<field name="Date3" type="date" indexed="false" stored="true" required="false"/>
When we execute a query with a document which has already been indexed, we get the following values returned in the SolrAdmin interface:
<date name="Date1">0001-01-01T00:00:00Z</date>
<date name="Date2">2010-04-10T08:21:18.281Z</date>
<date name="Date3">2007-12-01T03:09:41.093Z</date>
But when we inspect the C# object which gets returned with the SolrQueryResults, it shows the following:
Date1 : {01-01-0001 12:00:00 AM}
Date2 : null
Date3 : null
The first date is being represented as the datetime min value which is expected. But why are the other dates getting null values when these are valid dates in the UTC format?
Is it better to store the date fields as strings in Solr and use a copy field to store it in the solr date format and use this field for date range queries?

Check that you are returning the Date2 and Date3 fields in your SolrNet query results. e.g. Make sure that you are not limiting the fields with &fl parameter via SolrNet Fields QueryOptions or using a requestHandler on the Solr instance that is filtering fields and does not include those fields.

Please try the below code, Hope it helps
using SolrNet;
public List<ISolrQuery> BuildFitlerQuery(DateTime StartDate, DateTime EndDate, string FiledName)
{
var filter = new List<ISolrQuery>();
if (EndDate.Year != 1)// Will create query when end date value is also send
filter.Add(new SolrQueryByRange<DateTime?>(FiledName, StartDate, EndDate));
else
filter.Add(new SolrQueryByRange<DateTime?>(FiledName, StartDate, null));
return filter;
}

Related

How to solve Unparseable date:error in spring-boot

I having difficulty trying to solve an error with my date in Spring. I think i have exhausted almost all the solution on stack overflow an i still do not have a solution. I have implement a customDateEditor and i am still get the same error.
I am using the datepicker to select the date on the form.
Error
Failed to convert property value of type java.lang.String to required type java.util.Date for property date; nested exception is
java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "1 March, 2017"
Model
#NotNull(message = "Date field must not be blank.")
#DateTimeFormat(pattern = "dd-MM-yyyy")
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
Controller
#InitBinder
public void allowEmptyDateBinding( WebDataBinder binder )
{
// Custom String Editor. tell spring to set empty values as null instead of empty string.
binder.registerCustomEditor( String.class, new StringTrimmerEditor( true ));
//Custom Date Editor
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd-MM-yyyy");
simpleDateFormat.setLenient(false);
binder.registerCustomEditor( Date.class, new CustomDateEditor( simpleDateFormat,true));
}
Form
<input th:type="date" class="form-control input-sm datepicker" th:field="*{date}"
placeholder="Date Of Birth"/>
JS Script
$('.datepicker').pickadate({
autoclose: true,
Format: 'dd-MM-yyyy'
});
You are actually using pickadate.js rather than jquery-ui datepicker.
And according to documentation, you are supposed to give 'formatSubmit' property to ensure format of submitted date.
Another issue is your date format for javascript and Java code does not match.
Format 'dd-MM-yyyy' for SimpleDateFormat class will give 01-03-2017,
while for pickatedate.js you need to give 'dd-mm-yyyy' as format.
Therefore, for your "JS script" you should use
$('.datepicker').pickadate({
autoclose: true,
format: 'dd-MM-yyyy',
formatSubmit: 'dd-mm-yyyy'
});

LINQ - Buidling a search query

I am building up a search query for my customer search function:
I have all these fields passing into the function and wonder what is the best way to build up the LINQ expression. Some of the fields maybe an empty string and the search should be using "contains" instead of searching the exact field string
public List<Customer> SearchCustomer(
string membershipID,
string preferName,
string firstName,
string lastName,
string nric,
string phoneNumber,
string email,
DateTime dob,
string gender,
string address,
Boolean vip,
bool isDeleted)
You can manage multiple filter parameters in the following way:
var result = customerCollection.
.Where(c => membershipID != null ? c.membershipId.Contains(membershipID) : true)
.Where(c => preferName != null ? c.preferName.Contains(membershipID) : true)
...
.ToList();
I hope you get the idea

Why parse date not return as a string?

I query date from parse and see that my date type column return as json object
newsPublishDate: {
__type: "Date"
iso: "2015-10-20T11:41:00.000Z"
}
while createdAt column also a date type but return a String
createdAt: "2015-10-24T11:38:14.766Z"
how can i make parse return my date column as a string?
thank you so much.
#MichaelP try newsPublishDate.iso assuming the name of the variable that contains the JSON object is called newsPublishDate.

f:convertDateTime returns wrong date and time

I have a DB table with field from type DATE and i would like to show it on the user interface in this format 'dd.mm.yyyy hh:mm:ss'. I get it using Hibernate query and convert it using:
<f:convertDateTime pattern="dd.mm.yyyy hh:mm:ss" />
But the result is not what i expected.
for example:
8.6.2014 03:00:00 (from the DB) -> 08.00.2014 12:00:00 (in the user interface)
15.6.2014 12:00:00 (from the DB) -> 15.00.2014 12:00:00 (in the user interface)
I added in my web.xml
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
My timeZone is UTC+02:00
Thanks in advance for the help.
Month is represented with capital "M". In your case, it would be:
<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss" />
EDIT
You should add your timeZone too:
<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss" timeZone="GMT+2" />
EDIT 2
If it doesn't work, you can use SimpleDateFormat:
public static String dateToString(Date date, String format) throws ParseException {
SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
return sdf.format(date);
}
And then:
String newDate = dateToString(myDate, "dd.MM.yyyy HH:mm:ss");

Adding Programmatically datasource / dataset to LocalReport

Is there any way to add programmatically a datasource / dataset to a Microsoft.Reporting.WebForms.LocalReport when the report-XmlFile (*.rdlc) has no datasource / dataset definitions at design-time?
This works if I already have a datasource / dataset definition in my *.rdlc
C#
public byte[] RenderReport(string reportName, string reportFormat)
{
LocalReport report = LoadReport(reportName);
//Has same name like DataSet in *.rdlc
ReportDataSource rds = new ReportDataSource("DataSet1", getData());
report.DataSources.Clear();
report.DataSources.Add(rds);
return report.Render(reportName);
}
private DataTable getData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID",typeof(System.String)));
dt.Columns.Add(new DataColumn("NAME", typeof(System.String)));
dt.Rows.Add(new string[] { "1", "Me" });
return dt;
}
*.rdlc
<DataSources>
<DataSource Name="DataSource1">
<ConnectionProperties>
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields>
<Field Name="ID">
<DataField>ID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="NAME">
<DataField>NAME</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
But if I remove the datasource / dataset definition I get
{Microsoft.Reporting.DefinitionInvalidException: The definition of the
report '' is invalid. --->
Microsoft.ReportingServices.ReportProcessing.ReportPublishingException:
The Value expression for the text box ‘Textbox1’ refers to the field
‘ID’. Report item expressions can only refer to fields within the
current dataset scope or, if inside an aggregate, the specified
dataset scope. Letters in the names of fields must use the correct
case.}
Do I always have to create something like a "Dummy"-DataSource/DataSet or do I miss something in my code?
I hope there is another solution as manipulating the XML before rendering-process, any ideas?
Thanks!
You can't leave RDLC witout DataSets, if you are using it and RDLC is embedded in your project.
Either you leave DataSet fixed and change only it's items either try to load report definition from XML
// Valid XML with dynamic DataSources and DataSets
string s = #"<?xml version=""1.0"" encoding=""utf-8""?><Report ...>...</Report>";
report.LoadReportDefinition(new MemoryStream(Encoding.UTF8.GetBytes(s)));
return report.Render(reportName);

Resources