Using LIKE in search query I would like to search for words that contains the keyword when a user executes a search. I have tried to hook into hook_query_alter():

function MYMODULE_query_alter(&amp;$query) {
  // Check if this is a search query   
  if (!$query-&gt;hasTag('search_node')) {
    return;
  }

  $conditions = &amp;$query-&gt;conditions();
  $conditions = &amp;$conditions[1]['field']-&gt;conditions();
  // Change the condition to '%&lt;keyword&gt;%'
  // and add LIKE as operator
  $conditions[0]['value'] = "%" . $conditions[0]['value'] . "%";
  $conditions[0]['operator'] = 'LIKE';
}


I can alter the search query, but I'm not getting any results.

The modified query that gets executed looks like this:

SELECT FROM {search_index} i
  INNER JOIN {node} n ON n.nid = i.sid
  INNER JOIN {search_total} t ON i.word = t.word
  WHERE (n.status = :db_condition_placeholder_0)
    AND ((i.word LIKE :db_condition_placeholder_1 ESCAPE '\\'))
    AND (i.type = :db_condition_placeholder_2) 
  GROUP BY i.type, i.sid
  HAVING  (COUNT(*) &gt;= :matches)


And the placeholders in the SelectQuery object are set to:

[:db_condition_placeholder_0] =&gt; 1
[:db_condition_placeholder_1] =&gt; %liv%
[:db_condition_placeholder_2] =&gt; node


I can verify that the tables search_index and search_total both contain a couple of words that contain liv, so this should return some results.

I have also tried Fuzzy Search module, but I don't know how I can connect the provided search to the ordinary search form.

Notice that I have tried db_like(), but without any success.

I don't understand why it should be so hard to change the default search to search through the index using a LIKE rather than = condition?

Something like this should work if I only knew how to implement it:

$keyword = $_GET['s'];
$status = 1;
$types = array('article', 'contact');

db_query("SELECT node.nid FROM {node} n
  INNER JOIN {search_index} si 
    ON si.sid = n.nid 
    AND si.word LIKE :keyword
  INNER JOIN {search_dataset} sd ON sd.sid = n.nid
  WHERE n.status = :status AND n.type IN (:types)
  GROUP BY n.nid", array(
    ':keyword' =&gt; '%' . db_like($keyword) . '%',
    ':status' =&gt; $status,
    ':types' =&gt; $types
  )
);
you connect the the fuzzy search via search api pages module (or views).

when using views you can place the views search block in your desired region.

Manual instructions: (from fuzzy search)


From the main Search API configuration page, create a server using the Fuzzy Search service class.
Create an Index using the server you just created.
Click the Workflow Tab.
Enable "Complete entity view".
Enable the following processors: Both Fuzzy search processors, Ignore case, HTML filter, and Tokenizer.
Move the Fuzzy Search excerpt processor to the bottom of the list, and the Fuzzy Search search settings processor just above it.
The default settings should be fine.
You will need the Search API Pages module or Views to provide a place to search your site.
Go to the main Search API page,
Click Search Pages, add a search page, and configure with the index you created above, multiple terms for query type, and view mode as themed as search results.
For Views, make a new view using the default fuzzyseach index, add a page display and configure as desired.
Run cron to index your content. Visit the path for your search page.