search "performance“ message for user with link to pricing page

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy 2013-02-14 20:00:16 +01:00
parent 0db5022c47
commit 108f77c73d
2 changed files with 47 additions and 14 deletions

View File

@ -546,12 +546,33 @@ function template_preprocess_materio_search_api_results(array &$variables) {
// $variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
$variables['result_count'] = $results['result count'];
$variables['sec'] = round($results['performance']['complete'], 3);
$variables['search_performance'] = format_plural(
$results['result count'],
'The search found 1 result.', // in @sec seconds
'The search found @count results.', // in @sec seconds
array('@sec' => $variables['sec'])
);
if(isset($results['breves count'])){
$variables['search_performance'] = format_plural(
$results['breves count'],
'The search found 1 news ',
'The search found @count news '
);
$variables['search_performance'] .= format_plural(
$variables['result_count'] - $results['breves count'],
'and 1 associated matter.',
'and @count associated matters.'
);
$variables['search_performance'] .= format_plural(
$results['could results']['result count'],
' You could find 1 result with a ',
' You could find @count results with a '
);
$variables['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
}else{
$variables['search_performance'] = format_plural(
// $results['result count'],
$variables['result_count'],
'The search found 1 result.',
'The search found @count results.'
);
}
//dsm($variables, 'variables');
}

View File

@ -172,15 +172,17 @@ function materio_search_api_results_search(){
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
// dsm($index_machine_name, '$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');
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
foreach ($indexed_bundles as $bundle) {
$default_bundles[] = $bundle;
}
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');
@ -205,6 +207,16 @@ function materio_search_api_results_search(){
$query->filter($filter);
$results = $query->execute();
# 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))
->range($offset, $limit)
->filter($filter);
$could_results = $could_query->execute();
}
}
catch (SearchApiException $e) {
$ret['message'] = t('An error occurred while executing the search. Please try again or contact the site administrator if the problem persists.');
@ -243,6 +255,7 @@ function materio_search_api_results_search(){
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']));
@ -262,18 +275,17 @@ function materio_search_api_results_search(){
}
}
}
$results['breves count'] = $results['result count'];
$results['result count'] = count($items);
$results['could results'] = $could_results;
}
$ret['results']['#theme'] = 'materio_search_api_results';
/*
TODO choose index in module settings
*/
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
$ret['results']['#results'] = $results;
$ret['results']['#items'] = $items;
$ret['results']['#view_mode'] = $viewmode;
$ret['results']['#keys'] = $keys;