|
@@ -122,45 +122,22 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
function materio_search_api_results_search(){
|
|
function materio_search_api_results_search(){
|
|
- global $user;
|
|
|
|
-
|
|
|
|
//dsm("materio_search_api_results_search");
|
|
//dsm("materio_search_api_results_search");
|
|
|
|
+
|
|
|
|
+ // retreive typed words separated by slahes as a sentence
|
|
$args = func_get_args();
|
|
$args = func_get_args();
|
|
$typed = implode('/', $args);
|
|
$typed = implode('/', $args);
|
|
// dsm($typed, 'typed');
|
|
// dsm($typed, 'typed');
|
|
|
|
|
|
|
|
+ // remove query page params
|
|
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
|
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
|
//dsm($pages, '$pages');
|
|
//dsm($pages, '$pages');
|
|
if($pages[0]){
|
|
if($pages[0]){
|
|
$typed = str_replace($pages[0][0], '', $typed);
|
|
$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;
|
|
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')){
|
|
if(user_access('use materio search api')){
|
|
// switch index depending on key words type full text or taxonomy term (autocomplete selection)
|
|
// 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');
|
|
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
|
// dsm($viewmode, 'viewmode');
|
|
// dsm($viewmode, 'viewmode');
|
|
|
|
|
|
- if ($keys) {
|
|
|
|
|
|
+ // if ($keys) {
|
|
|
|
+ if ($typed) {
|
|
// TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
|
// TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
|
try {
|
|
try {
|
|
$limit = variable_get($viewmode.'_limite', '10');
|
|
$limit = variable_get($viewmode.'_limite', '10');
|
|
$offset = pager_find_page() * $limit; //$page*$limit;//
|
|
$offset = pager_find_page() * $limit; //$page*$limit;//
|
|
|
|
|
|
$query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
|
$query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
|
- ->keys(implode(' ', $keys))
|
|
|
|
|
|
+ // ->keys(implode(' ', $keys))
|
|
|
|
+ ->keys($typed)
|
|
->range($offset, $limit);
|
|
->range($offset, $limit);
|
|
|
|
|
|
if(count($bundles_filter)){
|
|
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
|
|
# in case of utilisateur search, run a real search to indicate how much items you could find
|
|
if(isset($could_index)){
|
|
if(isset($could_index)){
|
|
$could_query = search_api_query($could_index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
|
$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);
|
|
->range($offset, $limit);
|
|
// ->filter($filter);
|
|
// ->filter($filter);
|
|
|
|
|
|
@@ -287,7 +267,8 @@ function materio_search_api_results_search(){
|
|
$ret['results']['#results'] = $results;
|
|
$ret['results']['#results'] = $results;
|
|
$ret['results']['#items'] = $items;
|
|
$ret['results']['#items'] = $items;
|
|
$ret['results']['#view_mode'] = $viewmode;
|
|
$ret['results']['#view_mode'] = $viewmode;
|
|
- $ret['results']['#keys'] = $keys;
|
|
|
|
|
|
+ // $ret['results']['#keys'] = $keys;
|
|
|
|
+ $ret['results']['#keys'] = $typed;
|
|
|
|
|
|
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
|
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
|
|
|
|