highlighted the FOUND X RESULTS sentence

This commit is contained in:
Bachir Soussi Chiadmi 2014-07-02 18:21:39 +02:00
parent 9df43555ac
commit 5b26e36355
3 changed files with 67 additions and 42 deletions

View File

@ -763,43 +763,58 @@ function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
* *
* @see materio-search-api-results.tpl.php * @see materio-search-api-results.tpl.php
*/ */
function template_preprocess_materio_search_api_results(array &$variables) { function template_preprocess_materio_search_api_results(array &$vars) {
// dsm($variables, '$variables'); // dsm($vars, '$vars');
$results = $variables['results']; $results = $vars['results'];
$keys = $variables['keys']; $keys = $vars['keys'];
// $variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results'])); // $vars['items'] = $vars['index']->loadItems(array_keys($vars['results']['results']));
$variables['result_count'] = $results['result count']; $vars['result_count'] = $results['result count'];
$variables['sec'] = round($results['performance']['complete'], 3); $vars['sec'] = round($results['performance']['complete'], 3);
$vars['keywords'] = implode(', ', $vars['keys']);
if(isset($results['breves count'])){ if(isset($results['breves count'])){
$variables['search_performance'] = format_plural( $vars['perfascard'] = true;
$vars['search_performance'] = format_plural(
$results['breves count'], $results['breves count'],
'The search found 1 news ', 'The search found 1 news ',
'The search found @count news ' 'The search found @count news '
); );
$variables['search_performance'] .= format_plural( $vars['search_performance'] .= format_plural(
$variables['result_count'] - $results['breves count'], $vars['result_count'] - $results['breves count'],
'with 1 associated matter.', 'with 1 associated matter.',
'with @count associated matters.' 'with @count associated matters.'
); );
$variables['search_performance'] .= format_plural( $vars['search_performance'] .= format_plural(
$results['could results']['result count'], $results['could results']['result count'],
' You could find 1 result with a ', ' You could find 1 result with a ',
' You could find <strong>@count results</strong> with a ' ' You could find <strong>@count results</strong> with a '
); );
$variables['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187'); $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{ }else{
$variables['search_performance'] = format_plural( $vars['perfascard'] = false;
// $results['result count'],
$variables['result_count'], // $vars['search_performance'] = format_plural(
'The search found 1 result.', // // $results['result count'],
'The search found @count results.' // $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. @mat materials and @new news.', array(
"@count"=>$vars['result_count'],
"@keys"=>$vars['keywords'],
"@mat"=>4,
"@new"=>7)
); );
} }
//dsm($variables, 'variables'); //dsm($vars, '$vars');
} }

View File

@ -2,22 +2,22 @@
/** /**
* materiobase_search_autocomplete_dbselect() * materiobase_search_autocomplete_dbselect()
* *
* inspired by taxonomy_autocomplete() * inspired by taxonomy_autocomplete()
* *
* OBSOLETE : this fonction use a direct dbselect request to provide results forautocomplete * OBSOLETE : this fonction use a direct dbselect request to provide results forautocomplete
* *
*/ */
function materio_search_api_autocomplete_dbselect($typed = ''){ function materio_search_api_autocomplete_dbselect($typed = ''){
// If the request has a '/' in the search text, then the menu system will have // If the request has a '/' in the search text, then the menu system will have
// split it into multiple arguments, recover the intended $tags_typed. // split it into multiple arguments, recover the intended $tags_typed.
$args = func_get_args(); $args = func_get_args();
$typed = implode('/', $args); $typed = implode('/', $args);
/* /*
TODO riche serach engine + \\ etc gmail like TODO riche serach engine + \\ etc gmail like
*/ */
if ($typed != '') { if ($typed != '') {
// Part of the criteria for the query come from the field's own settings. // Part of the criteria for the query come from the field's own settings.
@ -56,7 +56,7 @@ function materio_search_api_autocomplete_dbselect($typed = ''){
/** /**
* materio_search_api_autocomplete_searchapi($typed = '') * materio_search_api_autocomplete_searchapi($typed = '')
* *
* GOOD one using searchapi (SOLR) * GOOD one using searchapi (SOLR)
*/ */
function materio_search_api_autocomplete_searchapi($typed = ''){ function materio_search_api_autocomplete_searchapi($typed = ''){
@ -64,7 +64,7 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
// split it into multiple arguments, recover the intended $tags_typed. // split it into multiple arguments, recover the intended $tags_typed.
$args = func_get_args(); $args = func_get_args();
$typed = implode('/', $args); $typed = implode('/', $args);
// dsm($typed, 'typed'); // dsm($typed, 'typed');
if ($typed != '') { if ($typed != '') {
@ -78,7 +78,7 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
global $language; global $language;
$index_machine_name = variable_get('autocompletesearchindex_'.$language->language, -1); $index_machine_name = variable_get('autocompletesearchindex_'.$language->language, -1);
$query = search_api_query($index_machine_name); $query = search_api_query($index_machine_name);
// $query_filter = $query->createFilter(); // $query_filter = $query->createFilter();
// $query_filter->condition('name', $tosearch); // $query_filter->condition('name', $tosearch);
// $query_filter->condition('type', 'article'); // $query_filter->condition('type', 'article');
@ -96,14 +96,14 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
//dsm($item, '$item'); //dsm($item, '$item');
//$term_matches[$item->tid] = check_plain($item->name); //$term_matches[$item->tid] = check_plain($item->name);
// $term_matches[check_plain($item->name)] = check_plain($item->name); // $term_matches[check_plain($item->name)] = check_plain($item->name);
// TODO: leave tags with nodes // TODO: leave tags with nodes
$term_matches[ trim(implode(' ', $adv_search_q[0]).' '.$last[1].$item->name)] = check_plain($item->name); $term_matches[ trim(implode(' ', $adv_search_q[0]).' '.$last[1].$item->name)] = check_plain($item->name);
$delta++; $delta++;
if($delta > 15) if($delta > 15)
break; break;
} }
drupal_json_output($term_matches); drupal_json_output($term_matches);
}else{ }else{
drupal_json_output(array()); drupal_json_output(array());
} }
@ -111,15 +111,15 @@ function materio_search_api_autocomplete_searchapi($typed = ''){
return; return;
} }
// dsm($term_matches, 'term_matches'); // dsm($term_matches, 'term_matches');
// return 'debug mode of materio_search_api_autocomplete_searchapi'; // return 'debug mode of materio_search_api_autocomplete_searchapi';
} }
/** /**
* materio_search_api_results_search() * materio_search_api_results_search()
* *
* *
*/ */
function materio_search_api_results_search(){ function materio_search_api_results_search(){
global $user; global $user;
@ -138,11 +138,11 @@ function materio_search_api_results_search(){
// else{ // else{
// $page = 0; // $page = 0;
// } // }
preg_match_all('/\s?[^\s]+\s?/', $typed, $words); preg_match_all('/\s?[^\s]+\s?/', $typed, $words);
// dsm($words, "words"); // dsm($words, "words");
// $match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' '); // $match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
// $replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ '); // $replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
foreach ($words[0] as $word) { foreach ($words[0] as $word) {
@ -197,7 +197,7 @@ function materio_search_api_results_search(){
// dsm($viewmode, 'viewmode'); // dsm($viewmode, 'viewmode');
if ($keys) { if ($keys) {
// 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;//
@ -244,7 +244,7 @@ function materio_search_api_results_search(){
// $results['results'] = $accessible_results; // $results['results'] = $accessible_results;
// $results['result count'] = count($accessible_results); // $results['result count'] = count($accessible_results);
if(user_access('use materio search api')){ if(user_access('use materio search api')){
$items = $index->loadItems(array_keys($results['results'])); $items = $index->loadItems(array_keys($results['results']));
@ -296,7 +296,7 @@ function materio_search_api_results_search(){
if (!empty($results['ignored'])) { if (!empty($results['ignored'])) {
drupal_set_message( drupal_set_message(
t('The following search keys are too short or too common and were therefore ignored: "@list".', t('The following search keys are too short or too common and were therefore ignored: "@list".',
array( '@list' => implode(t('", "'), $results['ignored']) ) ), array( '@list' => implode(t('", "'), $results['ignored']) ) ),
'warning' 'warning'
); );
@ -320,7 +320,7 @@ function materio_search_api_actuality(){
global $user; global $user;
if(isset($user->roles[1])){ if(isset($user->roles[1])){
$date_limit = strtotime('-6 month'); $date_limit = strtotime('-6 month');
// dsm(date('d m y', $date_limit)); // dsm(date('d m y', $date_limit));
} }
@ -361,7 +361,7 @@ function materio_search_api_actuality(){
if(isset($result['node'])){ if(isset($result['node'])){
foreach ($result['node'] as $nid => $n) { foreach ($result['node'] as $nid => $n) {
$breve = node_load($nid); $breve = node_load($nid);
if(!node_access('view', $breve)) if(!node_access('view', $breve))
continue; continue;
@ -377,7 +377,7 @@ function materio_search_api_actuality(){
} }
} }
} }
// drupal_set_title(t('Actualities')); // drupal_set_title(t('Actualities'));
drupal_set_title(t('')); drupal_set_title(t(''));

View File

@ -38,11 +38,21 @@
<?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) : ?>
<p class="search-performance"><?php print render($search_performance); ?></p> <?php if(!$perfascard): ?>
<p class="search-performance"><?php print render($search_performance); ?></P>
<?php endif; ?>
<?php //print render($spellcheck); ?> <?php //print render($spellcheck); ?>
<div class="search-results"> <div class="search-results">
<?php if($perfascard): ?>
<article class="search-performance <?php print ' view-mode-' . $variables['view_mode'];?>">
<div class="inner">
<p><?php print render($search_performance); ?></P>
</div>
</article>
<?php endif; ?>
<?php //dsm($items, '$items'); ?> <?php //dsm($items, '$items'); ?>
<?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 print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>