Is there any way to display a result count when doing Lucene searches? e.g. displaying 10 from 25 etc.

Comments

cpliakas’s picture

Hi Quinten.

Search Lucene API uses the standard global pager variables, so you have access to all this information. See the code below:


/**
 * Some function.
 */
function myfunction() {
  global $pager_page_array, $pager_total, $pager_total_items;

  // total number of items in result set.
  $pager_total_items[0];

  // total number of pages in the result set
  $pager_total[0];

  // the current page number
  $pager_page_array[0];

  // number of items per search results page
  luceneapi_variable_get('luceneapi_node', 'results_per_page');

}

You can use this information in your display logic to do what you illustrated above.

Thanks,
Chris

cpliakas’s picture

P.S to get the offset and first item, you would have to do the following:

/**
* Some function.
*/
function myfunction() {
  global $pager_page_array;

  // the current page number
  $page = $pager_page_array[0];

  // number of items per search results page
  $limit = luceneapi_variable_get('luceneapi_node', 'results_per_page');

  // zero based offset
  $offset = $limit * $page;

  // first item
  $first_item = $offset + 1;
}
Quentin’s picture

Hi Chris,

Thank you for your quick response! I have some basic PHP knowledge, but I am not much of a programmer.... is this supposed to go into the luceneapi.module file?

Thanks,

Quentin

cpliakas’s picture

Category: feature » support

Hi Quentin.

You do not want to modify the Search Lucene API files. It is generally bad practice to modify Drupal core code and contributed modules because it introduces unintended bugs and breaks upgrade paths. See the following post for more info : http://drupal.org/node/144376. Fortunately Search Lucene API does implement theme hooks fairly well, so you are able to modify what is displayed in a custom theme. Unfortunately a theming tutorial is out of the scope of this support request, but I will point you to the post at http://adaptivethemes.com/theme-your-search-results for a quick overview on how you can get this information into your templates. The pagination variables described above will be set in the preprocess function, and you can chose where to display it in the custom template.

Hope this points you in the right direction,
Chris

Quentin’s picture

Hi Chris,

Thank your for your quick response. I have been fiddling around with the code above, but I haven't managed to get it up and running as yet... I'll give it another go soon.. must be my PHP incompetence.. :-p

Thanks,

Quentin

walker2238’s picture

This is a bit off topic but another neat idea to expand on this would be by adding the words the user is searching for by using something like search_get_keys() I assume. That way you get the full phrase.

So you could have "(x-amount) results found for (my entered search term)."

cpliakas’s picture

Status: Active » Closed (fixed)

Marking as closed after a long period of inactivity.