0

I am trying to implement hook_search_api_multi_query_alter but it seems 'IN' operator does not work here. I have to check condition on array. Any pointers for start building custom operator.

function my_module_search_api_multi_query_alter(SearchApiMultiQueryInterface $query) {
$indexes = $query->getIndexes();
dpm($query->getFields());
if (isset($indexes['solr_content_index_dev'])) {
  $query->condition('solr_content_index_dev:nid', array(2918, 2367), 'IN');

}
}

1 Answer 1

0

Maybe this trick will help you. You can go upstream and implement hook_query_alter instead

function yourmodule_query_alter(&$query) {
if ($query->hasTag('search_api_db_search')) {
        $is_search = FALSE;
        $tables=$query->getTables();
        //dpm($tables);
        //only run for the query that really matters to you. Try to find something unique in this
          foreach ($tables as $table) {
            if ($table['table'] == 'search_api_db_your_important_table'  ) {
              $is_search = TRUE;
            }
          }

          if ($is_search) {
            //use query functions normally eg.
            $query->innerJoin('search_api_db_your_table', 'custom_table', "custom_table.item_id = t.item_id");
          }   
  }
}
1
  • search api in my case using apache solr.
    – arpitr
    Jan 22, 2015 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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