improved the message to people who access to the serach tool without an account
cf link from daily materiO'
This commit is contained in:
parent
488d4c19aa
commit
2e1e0cc05b
@ -96,7 +96,8 @@ function materio_search_api_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function materio_search_api_access_search(){
|
function materio_search_api_access_search(){
|
||||||
return user_access('use materio search api for breves') || user_access('use materio search api');
|
return true;
|
||||||
|
// return user_access('use materio search api for breves') || user_access('use materio search api');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -355,10 +356,6 @@ function materio_search_api_term_property_dup_name($term){
|
|||||||
return $term->name_field[$lang][0]['value'];
|
return $term->name_field[$lang][0]['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - - -- - - - - - - blocks - - - - - - - - - - -
|
* - - -- - - - - - - blocks - - - - - - - - - - -
|
||||||
*
|
*
|
||||||
@ -766,60 +763,79 @@ function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
|||||||
function template_preprocess_materio_search_api_results(array &$vars) {
|
function template_preprocess_materio_search_api_results(array &$vars) {
|
||||||
// dsm($vars, '$vars');
|
// dsm($vars, '$vars');
|
||||||
$results = $vars['results'];
|
$results = $vars['results'];
|
||||||
$keys = $vars['keys'];
|
|
||||||
|
|
||||||
// $vars['items'] = $vars['index']->loadItems(array_keys($vars['results']['results']));
|
if(isset($results['result count'])){
|
||||||
$vars['result_count'] = $results['result count'];
|
// $vars['items'] = $vars['index']->loadItems(array_keys($vars['results']['results']));
|
||||||
$vars['sec'] = round($results['performance']['complete'], 3);
|
$vars['result_count'] = $results['result count'];
|
||||||
|
$vars['sec'] = round($results['performance']['complete'], 3);
|
||||||
|
|
||||||
$vars['keywords'] = implode(', ', $vars['keys']);
|
$vars['keywords'] = $vars['keys'];
|
||||||
|
|
||||||
if(isset($results['breves count'])){
|
if(isset($results['breves count'])){
|
||||||
|
// for free users
|
||||||
|
$vars['perfascard'] = true;
|
||||||
|
$vars['search_performance'] = format_plural(
|
||||||
|
$results['breves count'],
|
||||||
|
'The search found 1 news ',
|
||||||
|
'The search found @count news '
|
||||||
|
);
|
||||||
|
$vars['search_performance'] .= format_plural(
|
||||||
|
$vars['result_count'] - $results['breves count'],
|
||||||
|
'with 1 associated matter.',
|
||||||
|
'with @count associated matters.'
|
||||||
|
);
|
||||||
|
$vars['search_performance'] .= format_plural(
|
||||||
|
$results['could results']['result count'],
|
||||||
|
' You could have found 1 result with a ',
|
||||||
|
' You could have found <strong>@count results</strong> with a '
|
||||||
|
);
|
||||||
|
$vars['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
|
||||||
|
|
||||||
|
$vars['search_performance'] .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
// for members
|
||||||
|
$vars['perfascard'] = false;
|
||||||
|
|
||||||
|
// $vars['search_performance'] = format_plural(
|
||||||
|
// // $results['result count'],
|
||||||
|
// $vars['result_count'],
|
||||||
|
// 'The search found 1 result ',
|
||||||
|
// 'The search found @count results '
|
||||||
|
// )
|
||||||
|
|
||||||
|
$vars['search_performance'] = t('The search found @count result(s) with keywords @keys.', array(
|
||||||
|
"@count"=>$vars['result_count'],
|
||||||
|
"@keys"=>$vars['keywords'])
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO indicate how many materials and how many news
|
||||||
|
// $vars['search_performance'] = t('The search found @count result(s) with keywords @keys. @mat materials and @new news.', array(
|
||||||
|
// "@count"=>$vars['result_count'],
|
||||||
|
// "@keys"=>$vars['keywords'],
|
||||||
|
// "@mat"=>4,
|
||||||
|
// "@new"=>7)
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//for anonymous
|
||||||
$vars['perfascard'] = true;
|
$vars['perfascard'] = true;
|
||||||
$vars['search_performance'] = format_plural(
|
|
||||||
$results['breves count'],
|
$perfoutput = t('Your can\'t access to the materiO\' search tool without an account.').'<br />';
|
||||||
'The search found 1 news ',
|
|
||||||
'The search found @count news '
|
$perfoutput .= format_plural(
|
||||||
);
|
|
||||||
$vars['search_performance'] .= format_plural(
|
|
||||||
$vars['result_count'] - $results['breves count'],
|
|
||||||
'with 1 associated matter.',
|
|
||||||
'with @count associated matters.'
|
|
||||||
);
|
|
||||||
$vars['search_performance'] .= format_plural(
|
|
||||||
$results['could results']['result count'],
|
$results['could results']['result count'],
|
||||||
' You could have found 1 result with a ',
|
' You could have found 1 result with a ',
|
||||||
' You could have found <strong>@count results</strong> with a '
|
' You could have found <strong>@count results</strong> with a '
|
||||||
);
|
);
|
||||||
$vars['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
|
$perfoutput .= l(t('full access to materiO\'.'), 'node/11187');
|
||||||
|
|
||||||
$vars['search_performance'] .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
$perfoutput .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
||||||
|
|
||||||
}else{
|
|
||||||
$vars['perfascard'] = false;
|
|
||||||
|
|
||||||
// $vars['search_performance'] = format_plural(
|
|
||||||
// // $results['result count'],
|
|
||||||
// $vars['result_count'],
|
|
||||||
// 'The search found 1 result ',
|
|
||||||
// 'The search found @count results '
|
|
||||||
// )
|
|
||||||
|
|
||||||
$vars['search_performance'] = t('The search found @count result(s) with keywords @keys.', array(
|
|
||||||
"@count"=>$vars['result_count'],
|
|
||||||
"@keys"=>$vars['keywords'])
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO indicate how many materials and how many news
|
|
||||||
// $vars['search_performance'] = t('The search found @count result(s) with keywords @keys. @mat materials and @new news.', array(
|
|
||||||
// "@count"=>$vars['result_count'],
|
|
||||||
// "@keys"=>$vars['keywords'],
|
|
||||||
// "@mat"=>4,
|
|
||||||
// "@new"=>7)
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
$vars['search_performance'] = $perfoutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//dsm($vars, '$vars');
|
//dsm($vars, '$vars');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,51 +156,55 @@ 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);
|
// potential results index for anonymous and free user
|
||||||
// dsm($index_machine_name, '$index_machine_name');
|
$could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||||
$default_bundles = array();
|
$could_index = search_api_index_load($index_machine_name);
|
||||||
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');
|
|
||||||
|
|
||||||
// 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'))
|
if(isset($index)){
|
||||||
// ->keys(implode(' ', $keys))
|
|
||||||
->keys($typed)
|
|
||||||
->range($offset, $limit);
|
|
||||||
|
|
||||||
if(count($bundles_filter)){
|
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||||
$filter = $query->createFilter('OR');
|
// dsm($index_machine_name, '$index_machine_name');
|
||||||
foreach ($bundles_filter as $type) {
|
$default_bundles = array();
|
||||||
$filter->condition('type', $type, '=');
|
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);
|
$bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
||||||
|
// dsm($bundles_filter, 'bundles_filter');
|
||||||
|
|
||||||
|
$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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// $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)){
|
||||||
$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'))
|
||||||
@ -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();
|
if(user_access('use materio search api for breves') || user_access('use materio search api')){
|
||||||
// foreach ($results['results'] as $nid => $entity) {
|
if(user_access('use materio search api')){
|
||||||
// if(node_access('view', node_load($nid)))
|
$items = $index->loadItems(array_keys($results['results']));
|
||||||
// $accessible_results[$nid] = $entity;
|
// dsm($items, 'items');
|
||||||
// }
|
// $count = $results['result count'];
|
||||||
// $results['results'] = $accessible_results;
|
}
|
||||||
// $results['result count'] = count($accessible_results);
|
else{
|
||||||
|
$items = array();
|
||||||
|
$breves = $index->loadItems(array_keys($results['results']));
|
||||||
|
foreach ($breves as $nid => $breve) {
|
||||||
|
|
||||||
|
if(!node_access('view', $breve))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$items[] = $breve;
|
||||||
if(user_access('use materio search api')){
|
$materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
||||||
$items = $index->loadItems(array_keys($results['results']));
|
// dsm($materiaux, 'materiaux');
|
||||||
// dsm($items, 'items');
|
if($materiaux){
|
||||||
// $count = $results['result count'];
|
foreach ($materiaux as $value) {
|
||||||
}else if(user_access('use materio search api for breves')){
|
if(!isset($could_results['results'][$value['target_id']]))
|
||||||
$items = array();
|
continue;
|
||||||
$breves = $index->loadItems(array_keys($results['results']));
|
$materiau = node_load($value['target_id']);
|
||||||
foreach ($breves as $nid => $breve) {
|
if(node_access('view', $materiau))
|
||||||
|
$items[] = $materiau;
|
||||||
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'];
|
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
||||||
$results['result count'] = count($items);
|
$ret['results']['#items'] = $items;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// for anonymous
|
||||||
$results['could results'] = $could_results;
|
$results['could results'] = $could_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dsm($typed, 'typed');
|
||||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
// for all case
|
||||||
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
|
||||||
$ret['results']['#results'] = $results;
|
$ret['results']['#results'] = $results;
|
||||||
$ret['results']['#items'] = $items;
|
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||||
$ret['results']['#view_mode'] = $viewmode;
|
|
||||||
// $ret['results']['#keys'] = $keys;
|
|
||||||
$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);
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
<?php //if (!empty($result_count)) : ?>
|
<?php //if (!empty($result_count)) : ?>
|
||||||
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
||||||
<?php if ($result_count) : ?>
|
<?php //if ($result_count) : ?>
|
||||||
<?php if(!$perfascard): ?>
|
<?php if(!$perfascard): ?>
|
||||||
<p class="search-performance"><?php print render($search_performance); ?></P>
|
<p class="search-performance"><?php print render($search_performance); ?></P>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@ -55,11 +55,13 @@
|
|||||||
<?php
|
<?php
|
||||||
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
||||||
?>
|
?>
|
||||||
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
<?php if ($result_count) : ?>
|
||||||
|
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php print $pager; ?>
|
<?php print $pager; ?>
|
||||||
<?php else : ?>
|
<?php //else : ?>
|
||||||
<p class="search-noresults"><?php print t('Your search yielded no results.');?></p>
|
<!-- <p class="search-noresults"><?php print t('Your search yielded no results.');?></p> -->
|
||||||
<?php endif; ?>
|
<?php //endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php //endif; ?>
|
<?php //endif; ?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user