Lucene Syntax to Respect Publish and Expire Dates

Description

If you are trying to do something, for instance with news items, that need to respect both a publish and expire date, you just need some simple Lucene syntax. It requires a condition to be required for each field.

In this example, it basically translates to "get me content with a publish date that's either today or earlier, AND that has an expire date equal to today or some time way in the future." Using 2000 and 2100 as the bookend years is completely arbitrary on my part. You could also modify the $date.format() pattern to include the time, if your fields are that specific.

Code

+newsItem.publishDate:[01/01/2000 TO $date.format('MM/dd/yyyy',$date.getDate())] +newsItem.expireDate:[$date.format('MM/dd/yyyy',$date.getDate()) TO 12/31/2100]