|
@@ -127,7 +127,6 @@ function materio_search_api_results_search(){
|
|
// retreive typed words separated by slahes as a sentence
|
|
// 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');
|
|
|
|
|
|
|
|
// remove query page params
|
|
// remove query page params
|
|
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
|
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
|
@@ -135,6 +134,7 @@ function materio_search_api_results_search(){
|
|
if($pages[0]){
|
|
if($pages[0]){
|
|
$typed = str_replace($pages[0][0], '', $typed);
|
|
$typed = str_replace($pages[0][0], '', $typed);
|
|
}
|
|
}
|
|
|
|
+ // dsm($typed, 'typed');
|
|
|
|
|
|
global $language;
|
|
global $language;
|
|
global $user;
|
|
global $user;
|
|
@@ -156,50 +156,54 @@ function materio_search_api_results_search(){
|
|
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
|
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
|
// dsm($index_machine_name, '$index_machine_name');
|
|
// dsm($index_machine_name, '$index_machine_name');
|
|
$index = search_api_index_load($index_machine_name);
|
|
$index = search_api_index_load($index_machine_name);
|
|
-
|
|
|
|
- $could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
|
|
|
- $could_index = search_api_index_load($index_machine_name);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
|
|
|
- // dsm($index_machine_name, '$index_machine_name');
|
|
|
|
- $default_bundles = array();
|
|
|
|
- if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
|
|
|
- $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
|
|
|
- foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- $bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
|
|
|
- // dsm($bundles_filter, 'bundles_filter');
|
|
|
|
-
|
|
|
|
- $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
|
|
|
- // dsm($viewmode, 'viewmode');
|
|
|
|
|
|
+ // potential results index for anonymous and free user
|
|
|
|
+ $could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
|
|
|
+ $could_index = search_api_index_load($index_machine_name);
|
|
|
|
|
|
- // if ($keys) {
|
|
|
|
if ($typed) {
|
|
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 {
|
|
|
|
+
|
|
|
|
+ $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
|
|
|
+ // dsm($viewmode, 'viewmode');
|
|
|
|
+
|
|
$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'))
|
|
|
|
- // ->keys(implode(' ', $keys))
|
|
|
|
- ->keys($typed)
|
|
|
|
- ->range($offset, $limit);
|
|
|
|
|
|
+ if(isset($index)){
|
|
|
|
|
|
- if(count($bundles_filter)){
|
|
|
|
- $filter = $query->createFilter('OR');
|
|
|
|
- foreach ($bundles_filter as $type) {
|
|
|
|
- $filter->condition('type', $type, '=');
|
|
|
|
|
|
+ // $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
|
|
|
+ // dsm($index_machine_name, '$index_machine_name');
|
|
|
|
+ $default_bundles = array();
|
|
|
|
+ if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
|
|
|
+ $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
|
|
|
+ foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
|
}
|
|
}
|
|
- // dsm($filter, 'filter');
|
|
|
|
- $query->filter($filter);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- // $query->setOption('search_api_bypass_access', true);
|
|
|
|
- $query->setOption('search_api_access_account', $user);
|
|
|
|
|
|
+ $bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
|
|
|
+ // dsm($bundles_filter, 'bundles_filter');
|
|
|
|
|
|
- $results = $query->execute();
|
|
|
|
|
|
+ $query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
|
|
|
+ // ->keys(implode(' ', $keys))
|
|
|
|
+ ->keys($typed)
|
|
|
|
+ ->range($offset, $limit);
|
|
|
|
+
|
|
|
|
+ if(count($bundles_filter)){
|
|
|
|
+ $filter = $query->createFilter('OR');
|
|
|
|
+ foreach ($bundles_filter as $type) {
|
|
|
|
+ $filter->condition('type', $type, '=');
|
|
|
|
+ }
|
|
|
|
+ // dsm($filter, 'filter');
|
|
|
|
+ $query->filter($filter);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // $query->setOption('search_api_bypass_access', true);
|
|
|
|
+ $query->setOption('search_api_access_account', $user);
|
|
|
|
+
|
|
|
|
+ $results = $query->execute();
|
|
|
|
+ }
|
|
|
|
|
|
# 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)){
|
|
@@ -217,58 +221,56 @@ function materio_search_api_results_search(){
|
|
$ret['message'] = t('An error occurred while executing the search. Please try again or contact the site administrator if the problem persists.');
|
|
$ret['message'] = t('An error occurred while executing the search. Please try again or contact the site administrator if the problem persists.');
|
|
watchdog('materiobasemod', 'search error: !msg.', array('!msg' => $e->getMessage()), WATCHDOG_ERROR, l(t('search page'), $_GET['q']));
|
|
watchdog('materiobasemod', 'search error: !msg.', array('!msg' => $e->getMessage()), WATCHDOG_ERROR, l(t('search page'), $_GET['q']));
|
|
}
|
|
}
|
|
-
|
|
|
|
// dsm($results, 'results');
|
|
// dsm($results, 'results');
|
|
|
|
|
|
- // $accessible_results = array();
|
|
|
|
- // foreach ($results['results'] as $nid => $entity) {
|
|
|
|
- // if(node_access('view', node_load($nid)))
|
|
|
|
- // $accessible_results[$nid] = $entity;
|
|
|
|
- // }
|
|
|
|
- // $results['results'] = $accessible_results;
|
|
|
|
- // $results['result count'] = count($accessible_results);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if(user_access('use materio search api')){
|
|
|
|
- $items = $index->loadItems(array_keys($results['results']));
|
|
|
|
- // dsm($items, 'items');
|
|
|
|
- // $count = $results['result count'];
|
|
|
|
- }else if(user_access('use materio search api for breves')){
|
|
|
|
- $items = array();
|
|
|
|
- $breves = $index->loadItems(array_keys($results['results']));
|
|
|
|
- foreach ($breves as $nid => $breve) {
|
|
|
|
-
|
|
|
|
- if(!node_access('view', $breve))
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- $items[] = $breve;
|
|
|
|
- $materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
|
|
|
- // dsm($materiaux, 'materiaux');
|
|
|
|
- if($materiaux){
|
|
|
|
- foreach ($materiaux as $value) {
|
|
|
|
- if(!isset($could_results['results'][$value['target_id']]))
|
|
|
|
- continue;
|
|
|
|
- $materiau = node_load($value['target_id']);
|
|
|
|
- if(node_access('view', $materiau))
|
|
|
|
- $items[] = $materiau;
|
|
|
|
|
|
+ if(user_access('use materio search api for breves') || user_access('use materio search api')){
|
|
|
|
+ if(user_access('use materio search api')){
|
|
|
|
+ $items = $index->loadItems(array_keys($results['results']));
|
|
|
|
+ // dsm($items, 'items');
|
|
|
|
+ // $count = $results['result count'];
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ $items = array();
|
|
|
|
+ $breves = $index->loadItems(array_keys($results['results']));
|
|
|
|
+ foreach ($breves as $nid => $breve) {
|
|
|
|
+
|
|
|
|
+ if(!node_access('view', $breve))
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ $items[] = $breve;
|
|
|
|
+ $materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
|
|
|
+ // dsm($materiaux, 'materiaux');
|
|
|
|
+ if($materiaux){
|
|
|
|
+ foreach ($materiaux as $value) {
|
|
|
|
+ if(!isset($could_results['results'][$value['target_id']]))
|
|
|
|
+ continue;
|
|
|
|
+ $materiau = node_load($value['target_id']);
|
|
|
|
+ if(node_access('view', $materiau))
|
|
|
|
+ $items[] = $materiau;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ $results['breves count'] = $results['result count'];
|
|
|
|
+ $results['result count'] = count($items);
|
|
|
|
+ $results['could results'] = $could_results;
|
|
}
|
|
}
|
|
|
|
|
|
- $results['breves count'] = $results['result count'];
|
|
|
|
- $results['result count'] = count($items);
|
|
|
|
|
|
+ $ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
|
|
|
+ $ret['results']['#items'] = $items;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ // for anonymous
|
|
$results['could results'] = $could_results;
|
|
$results['could results'] = $could_results;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- $ret['results']['#theme'] = 'materio_search_api_results';
|
|
|
|
- $ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
|
|
|
|
|
+ // dsm($typed, 'typed');
|
|
|
|
+ // for all case
|
|
$ret['results']['#results'] = $results;
|
|
$ret['results']['#results'] = $results;
|
|
- $ret['results']['#items'] = $items;
|
|
|
|
- $ret['results']['#view_mode'] = $viewmode;
|
|
|
|
- // $ret['results']['#keys'] = $keys;
|
|
|
|
|
|
+ $ret['results']['#theme'] = 'materio_search_api_results';
|
|
$ret['results']['#keys'] = $typed;
|
|
$ret['results']['#keys'] = $typed;
|
|
|
|
+ $ret['results']['#view_mode'] = $viewmode;
|
|
|
|
+
|
|
|
|
|
|
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);
|
|
|
|
|