Showing posts with label strings. Show all posts
Showing posts with label strings. Show all posts

13 August 2012

Solr date formats in C#

The Solr search engine requires dates to be in the UTC format. Using C# to create a Solr crawler, I came across a challenge as the engine would not accept the default dates. It kept throwing errors: "Error adding field". Some research revealed that Solr expects dates to always end with the "Z" character. This handy page showed the different String.Format() patterns to get just about any date string you need. This one worked for Solr:
var date = String.Format("{0:yyyy-MM-ddTHH:mm:ss.fffffffZ}", 
    dateObjectToFormat);
This produces a date in this format in Solr:
2010-03-09T00:00:00Z
Check out this documentation on the Solr date formats.

04 November 2008

Java String Comparison

One little gotcha in Java is the string comparisons: Using the equality check == will tell you if the two variables are referencing the same object, not whether their string values are the same. To do a string comparison, use something such as this,

 if (string1.equalsIgnoreCase(string2)) {
//... do something
}

Otherwise you'll be wondering why your code isn't working ;)