diff --git a/materio_search_api.pages.inc b/materio_search_api.pages.inc index d5996460..bb9372a4 100755 --- a/materio_search_api.pages.inc +++ b/materio_search_api.pages.inc @@ -122,45 +122,22 @@ function materio_search_api_autocomplete_searchapi($typed = ''){ * */ function materio_search_api_results_search(){ - global $user; - //dsm("materio_search_api_results_search"); + + // retreive typed words separated by slahes as a sentence $args = func_get_args(); $typed = implode('/', $args); // dsm($typed, 'typed'); + // remove query page params preg_match_all('/\?page=([0-9]+)/', $typed, $pages); //dsm($pages, '$pages'); if($pages[0]){ $typed = str_replace($pages[0][0], '', $typed); - // $page = $pages[1][0]; } - // else{ - // $page = 0; - // } - - preg_match_all('/\s?[^\s]+\s?/', $typed, $words); - // dsm($words, "words"); - - - // $match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' '); - // $replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ '); - foreach ($words[0] as $word) { - // dsm($word); - $word = trim($word); - // $word = str_replace($match, $replace, $word); - // dsm($word, 'word'); - $keys[] = $word; - } - // dsm($keys, 'keys'); global $language; - - // if(user_access('use materio search api')){ - - // }else if(user_access('use materio search api for breves')){ - - // } + global $user; if(user_access('use materio search api')){ // switch index depending on key words type full text or taxonomy term (autocomplete selection) @@ -198,14 +175,16 @@ function materio_search_api_results_search(){ $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full'); // dsm($viewmode, 'viewmode'); - if ($keys) { + // if ($keys) { + if ($typed) { // TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful try { $limit = variable_get($viewmode.'_limite', '10'); $offset = pager_find_page() * $limit; //$page*$limit;// $query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct')) - ->keys(implode(' ', $keys)) + // ->keys(implode(' ', $keys)) + ->keys($typed) ->range($offset, $limit); if(count($bundles_filter)){ @@ -225,7 +204,8 @@ function materio_search_api_results_search(){ # in case of utilisateur search, run a real search to indicate how much items you could find if(isset($could_index)){ $could_query = search_api_query($could_index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct')) - ->keys(implode(' ', $keys)) + // ->keys(implode(' ', $keys)) + ->keys($typed) ->range($offset, $limit); // ->filter($filter); @@ -287,7 +267,8 @@ function materio_search_api_results_search(){ $ret['results']['#results'] = $results; $ret['results']['#items'] = $items; $ret['results']['#view_mode'] = $viewmode; - $ret['results']['#keys'] = $keys; + // $ret['results']['#keys'] = $keys; + $ret['results']['#keys'] = $typed; drupal_set_title(''.check_plain($typed), PASS_THROUGH);