2

I'm trying to create a programmatic Search API query. I've successfully created one which looks for all nodes which are published:

  $index = search_api_index_load("node_index");
  $myQuery=new SearchApiQuery($index);
  $myQuery->condition('status', '1', '=');
  $data=$myQuery->execute();
  $results=$data['results'];

However the condition that I want to search for is to find all nodes with a certain date on a date field.

The problem is I can't work out how the Search API stores dates. I've tried UNIX time stamps:

  $myQuery->condition('field_application_end_date', '1411084800', '=');

And the PHP date format that is stored on the nodes however neither returns any results.

  $myQuery->condition('field_application_end_date', '2014-10-01T00:00:00', '=');

Can someone explain how the Search API stores dates?

I've been digging through the module to try and work out how it's done, but it's a little out of my league.

2

Try

$myQuery->condition('field_application_end_date:value', '1411084800', '=');

Search API stores the dates as timestamps, so you're right there, but you forgot the 'value' after the field. If you want to use the 'to' date, use 'value2'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.