4

I've successfully installed the search api module in drupal 7. I installed solar and it works fine. I need to create a custom search form that has various fields and those fields performs search only on the relitive field.

This means that if i have a content type with the following fields:

"job requested"

"previous exerience"

"city"

I want a searchh page with the same fields and when the user enter a value in the "city" field, it searches for that data only in that field: if I search the "city" field for "milan" I want to find only nodes with the word "milan" entered in the field "city" and not with the word "milan" entered in the body.

I think I need separete indexes for each fields, but structure the two forms?

1 Answer 1

2

You don't need separated indexes. In you callback handler, you need to build a new SearchApiQueryInterface instance and set conditions on the field using its condition method.

$index = search_api_index_load('custom_index_machine_name');
$query = $index->query(array(
  'language' => $GLOBALS['language']->language,
  'search id' => 'custom-search',
));
foreach($form_state['values']['filters'] as $field => $value) {
  if (!empty($value)) {
    $query->condition($field, $value);
  }
}
$result = $query->execute();

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.