I have created Search page which searches Products (Content type) by selecting few option drop down menus (those are selecting taxonomy terms), but also i have an text input field, which is supposed to narrow or define search by keywords.
Now problem is that i need to search several fields at same time.
This script works perfectly (snippet):
$keywords=$_POST ['keywords'];
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'product')
->fieldCondition('field_main_category', 'tid', $category, 'IN')
->fieldCondition('field_sku', 'value','%'. $keywords .'%', 'LIKE');
$result = $query->execute();
I got all the product that are matching user entry, even if partial (those %). But i need to query some other fields too (description and name), to search for terms that user may enter.
But, problem is that i must have one input field, and user may target 3 different fields, so three fieldConditions for same term will cause nothing to be found, because selection is excluding all if term is not found in one field.
Could I,some way, write EntityFieldQuery query in a way to tell it to "forget" condition if keyword is not found ? (like in bellow example)
$keywords=$_POST ['keywords'];
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'product')
->fieldCondition('field_main_category', 'tid', $category, 'IN')
->fieldCondition('field_sku', 'value','%'. $keywords .'%', 'LIKE');
->fieldCondition('field_name', 'value','%'. $keywords .'%', 'LIKE');
->fieldCondition('field_description', 'value','%'. $keywords .'%', 'LIKE');
$result = $query->execute();
Other workaround could be to look all three fields in one place, if i could get combined fields in one condition query (this could be done by hand, by adding another field only for search terms that will be filled with tags that will be searchable summary of all 3 fields, but i am hoping to find the way not to create more field and content, if possible).
Any suggestions or experiences with that ? Thanks!