I am getting the following error when trying to use sortable title and type fields in apachesolr_views with Style:table

Fatal error: Call to undefined method apachesolr_views_query::add_orderby() in /sites/all/modules/views/handlers/views_handler_field.inc on line 115

I was able to get sorting working by copying the add_sort method in apachesolr_views_query and adding the $table parameter that the call from views_handler_field.inc expects.

CommentFileSizeAuthor
#13 849650-13.patch1.51 KBrjbrown99
#8 bug-849650-8.patch1.31 KBbazzic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scotjam’s picture

I only get this error when I trying to add Global: Random sort. Other field sorting works fine.

Error...

An error occurred at /admin/build/views/ajax/preview/custom_search4.

Error Description:
Fatal error: Call to undefined method apachesolr_views_query::add_orderby() in C:\www\sites\all\modules\views\handlers\views_handler_sort_random.inc on line 20

drewish’s picture

Can't tell if that functionality is actually implemented in the ApacheSolr module at this point. This blog post might have some clues on how to implement it. In a comment, Rober Douglas notes that the schema changes aren't needed any more: http://realize.be/random-results-apache-solr-and-drupal

wuwei23’s picture

I'm getting a related error:

Fatal error: Call to undefined method apachesolr_views_query::add_orderby() in /var/www/pastonline2/sites/default/modules/views/handlers/views_handler_field.inc on line 122

This is running the latest dev releases of Views 3, apachesolr, and apachesolr_views.

In case it helps, here's an export of the view:

$view = new view;
$view->name = 'search_test';
$view->description = 'Search test';
$view->tag = '';
$view->base_table = 'apachesolr_node';
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'type' => 'type',
  'tid_1' => 'tid_1',
  'tid' => 'tid',
);
$handler->display->display_options['style_options']['default'] = 'title';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 1,
    'align' => '',
    'separator' => '',
  ),
  'type' => array(
    'sortable' => 0,
    'align' => '',
    'separator' => '',
  ),
  'tid_1' => array(
    'align' => '',
    'separator' => '',
  ),
  'tid' => array(
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* Field: Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'apachesolr_node_node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Apache Solr: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'apachesolr_node';
$handler->display->display_options['fields']['type']['field'] = 'type';
$handler->display->display_options['fields']['type']['label'] = '';
$handler->display->display_options['fields']['type']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['type']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['type']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['type']['alter']['trim'] = 0;
$handler->display->display_options['fields']['type']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['type']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['type']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['type']['alter']['html'] = 0;
$handler->display->display_options['fields']['type']['hide_empty'] = 0;
$handler->display->display_options['fields']['type']['empty_zero'] = 0;
$handler->display->display_options['fields']['type']['link_to_node'] = 0;
$handler->display->display_options['fields']['type']['machine_name'] = 0;
/* Field: Taxonomy: All terms */
$handler->display->display_options['fields']['tid_1']['id'] = 'tid_1';
$handler->display->display_options['fields']['tid_1']['table'] = 'apachesolr_node_term_node';
$handler->display->display_options['fields']['tid_1']['field'] = 'tid';
$handler->display->display_options['fields']['tid_1']['label'] = 'Year';
$handler->display->display_options['fields']['tid_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['tid_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['tid_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['tid_1']['link_to_taxonomy'] = 0;
$handler->display->display_options['fields']['tid_1']['limit'] = 1;
$handler->display->display_options['fields']['tid_1']['vids'] = array(
  '4' => 4,
  '1' => 0,
  '2' => 0,
  '3' => 0,
  '5' => 0,
);
/* Field: Taxonomy: All terms */
$handler->display->display_options['fields']['tid']['id'] = 'tid';
$handler->display->display_options['fields']['tid']['table'] = 'apachesolr_node_term_node';
$handler->display->display_options['fields']['tid']['field'] = 'tid';
$handler->display->display_options['fields']['tid']['label'] = 'Authors';
$handler->display->display_options['fields']['tid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['tid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['tid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['tid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['tid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['tid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['tid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['tid']['alter']['html'] = 0;
$handler->display->display_options['fields']['tid']['hide_empty'] = 0;
$handler->display->display_options['fields']['tid']['empty_zero'] = 0;
$handler->display->display_options['fields']['tid']['link_to_taxonomy'] = 1;
$handler->display->display_options['fields']['tid']['limit'] = 1;
$handler->display->display_options['fields']['tid']['vids'] = array(
  '1' => 1,
  '2' => 0,
  '3' => 0,
  '4' => 0,
  '5' => 0,
);
/* Sort criterion: Apache Solr: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'apachesolr_node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['exposed'] = TRUE;
$handler->display->display_options['sorts']['title']['expose']['label'] = 'Apache Solr: Title';
/* Filter: Apache Solr: Search */
$handler->display->display_options['filters']['text']['id'] = 'text';
$handler->display->display_options['filters']['text']['table'] = 'apachesolr_node';
$handler->display->display_options['filters']['text']['field'] = 'text';
$handler->display->display_options['filters']['text']['exposed'] = TRUE;
$handler->display->display_options['filters']['text']['expose']['operator'] = 'text_op';
$handler->display->display_options['filters']['text']['expose']['label'] = 'Apache Solr: Search';
$handler->display->display_options['filters']['text']['expose']['identifier'] = 'text';
/* Filter: Apache Solr: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'apachesolr_node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'book' => 'book',
  'ephemera' => 'ephemera',
  'journal' => 'journal',
  'thesis' => 'thesis',
);
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
$handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['label'] = 'Apache Solr: Type';
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
$handler->display->display_options['filters']['type']['expose']['remember'] = 1;
$handler->display->display_options['filters']['type']['expose']['single'] = 0;
$handler->display->display_options['filters']['type']['expose']['reduce'] = 1;
sethviebrock’s picture

Same issue as #1, and yes, only on Global: Random sort.

eme’s picture

I am getting this error even without the random, running last Views dev version, and last apachesolr dev version... (and right version of apache solr).

Rob van den Bogaard’s picture

Also getting this error (not only Global: Random sort) and currently digging into the code.

puzl’s picture

Same issue here. I'll dig in it more deeper.

Any findings, Rob?

bazzic’s picture

FileSize
1.31 KB

The original bug report has to do with click sorting, so if you're seeing this error elsewhere, this patch probably won't work for you.

I have taken a closer look at this, and it looks like the problem has to do with a missing click_sort method in the apachesolr field handlers. All of the apachesolr field handlers are extending from views handlers, so the click_sort method from views_handler_field is getting called, which in turn looks for the add_orderby method.

Now, the click_sort method DOES exist in apachesolr_views_handler_field_generic, which I assume was created to be used by all of the field handlers. However, simply extending from apachesolr_views_handler_field_generic doesn't work. I have attached a patch which adds the click_sort method to apachesolr_views_handler_field_title. You can use the same technique for other apachesolr field handlers (which shows why it would be nice to contain overridden methods like this in a generic handler, say apachesolr_views_handler_field_generic).

Rob van den Bogaard’s picture

I'm afraid I got a little bit out of sync with this issue. We have things working at the moment, but I don't remember specificly how we solved this one.

rjbrown99’s picture

Status: Active » Needs review

Patch here, changing status.

brycesenz’s picture

I get this error when trying add a "Sort by: Global Random" to my ApacheSolr view (same as post #4).

The patch does not fix that error.

rjbrown99’s picture

Title: add_orderby method missing in class apachesolr_views_query » Global: Random sort bug and add_orderby method missing in class apachesolr_views_query
Status: Needs review » Needs work

OK, so about random sorting.

I'm using apachesolr 2.x, with a schema.xml file of drupal-2.0-beta4. The really helpful link here was post #2 that points to how Solr deals with random ordering. In my schema file, I see this (in two places, I pasted then in here together):

    <!-- A random sort type -->
    <fieldType name="rand" class="solr.RandomSortField" indexed="true" />
    <!-- A random sort field -->
     <dynamicField name="random_*" type="rand" indexed="true" stored="true"/>

That's a good thing, and I checked my Solr index and I also see a field type of RAND. In the default Solr admin page, schema browser, I see it under dynamic fields (RANDOM_*). Per the docs, this is a dynamic field named random_*, where the * is the seed value for the randomness. So the idea is to pass along a different seed each time to get random sort results.

Looking at that post from #2, it shows that we want to wind up with "&sort=random_127789 desc" as part of the query, where 127789 is a random string that acts as the seed. So the first place to look is apachesolr_views_query.inc, the function add_sort. You can see that we want $field to be passed in as "random_NUMBER", so the $this->_sorts[] is set to random_NUMBER asc (or desc). That would seem to achieve the desired random sort order.

This part seems quite easy to create as a new sort handler, taking over the query() and sending rand_WHATEVER to the add_sort. I'm going to add a handler and roll up a patch, I have this working.

rjbrown99’s picture

Status: Needs work » Needs review
FileSize
1.51 KB

Here's a patch. I did not remove the Global: Random Sort as I'm not sure where that comes from. I also did not add an add_orderby() function as it was not necessary to make this work.

What I DID do was to add support for random sorts. After patching you should see a new sort criteria of "Apache Solr: Random". Adding that as a sort now gives you random results. This patch is against 6.x-1.x-dev Feb 25, which as of this post is the latest version posted on the main module page.

Scott Reynolds’s picture

Global: Random is added by views.view.inc and its Global. I do not believe it is possible to remove it without removing it from SQL sorts.

It might be worth opening a Views issue and figuring out how to make query handler specific Globals

ShaneOnABike’s picture

Issue tags: +views, +apache solr, +default sort

I'm getting this error without the global random value as well.

I noticed that this happens when I use a table viewed output with a Default sorting on one of the items being output. Can anyone help me with this I really could use it.

If I change the Default sort to None the error goes away, but then when I click on one of the headings to sort I basically get the error again :/

Error when selecting a default sort:

An error occurred at /admin/build/views/ajax/preview/local_product.

Error Description: 
Fatal error:  Call to undefined method apachesolr_views_query::add_orderby() in /somepath/views/handlers/views_handler_field.inc on line 124

Error when clicking on table sort:

An error occurred at /admin/build/views/ajax/preview/local_product/page_1?order=name&amp;sort=asc&amp;display_id=page_1&amp;args=&am
p;live_preview=1&amp;form_build_id=form-4b45fa3c2888abb5b62974d655f5f1e3&amp;form_token=13efc4f9f28268d1da1e3507c2eccf34&amp;form_id
=views_ui_preview_form&amp;js=1.

Error Description: 
Fatal error:  Call to undefined method apachesolr_views_query::add_orderby() in /somepath/views/handlers/views_handler_field.inc on line 124

*Here's my view:*

$view = new view;
$view->name = 'local_product';
$view->description = 'What\'s grown locally';
$view->tag = '';
$view->base_table = 'apachesolr_node';
$view->human_name = '';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'field_photo_fid' => 'field_photo_fid',
  'title' => 'title',
  'name' => 'name',
  'snippet' => 'snippet',
  'field_point_of_sale_nid' => 'field_point_of_sale_nid',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'field_photo_fid' => array(
    'align' => 'views-align-center',
    'separator' => '',
  ),
  'title' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'name' => array(
    'sortable' => 1,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'snippet' => array(
    'align' => '',
    'separator' => '',
  ),
  'field_point_of_sale_nid' => array(
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 0;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['style_options']['empty_table'] = 0;
/* Field: Content: Photo (field_photo) */
$handler->display->display_options['fields']['field_photo_fid']['id'] = 'field_photo_fid';
$handler->display->display_options['fields']['field_photo_fid']['table'] = 'apachesolr_node_node_data_field_photo';
$handler->display->display_options['fields']['field_photo_fid']['field'] = 'field_photo_fid';
$handler->display->display_options['fields']['field_photo_fid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_photo_fid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_photo_fid']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['link_to_node'] = 0;
$handler->display->display_options['fields']['field_photo_fid']['label_type'] = 'none';
$handler->display->display_options['fields']['field_photo_fid']['format'] = 'product_search_result_thumb_linked';
$handler->display->display_options['fields']['field_photo_fid']['multiple']['group'] = 1;
$handler->display->display_options['fields']['field_photo_fid']['multiple']['multiple_number'] = '1';
$handler->display->display_options['fields']['field_photo_fid']['multiple']['multiple_reversed'] = 0;
/* Field: Product name */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'apachesolr_node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['ui_name'] = 'Product name';
$handler->display->display_options['fields']['title']['label'] = 'Product name';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = 1;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'apachesolr_node_users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Farm name';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
/* Field: Apache Solr: Search Snippet */
$handler->display->display_options['fields']['snippet']['id'] = 'snippet';
$handler->display->display_options['fields']['snippet']['table'] = 'apachesolr_node';
$handler->display->display_options['fields']['snippet']['field'] = 'snippet';
$handler->display->display_options['fields']['snippet']['label'] = '';
$handler->display->display_options['fields']['snippet']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['snippet']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['snippet']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['snippet']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['snippet']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['snippet']['alter']['trim'] = 0;
$handler->display->display_options['fields']['snippet']['alter']['html'] = 0;
$handler->display->display_options['fields']['snippet']['hide_empty'] = 0;
$handler->display->display_options['fields']['snippet']['empty_zero'] = 0;
$handler->display->display_options['fields']['snippet']['num_snippets'] = '1';
$handler->display->display_options['fields']['snippet']['fragsize'] = '100';
/* Field: Content: Point of Sale (field_point_of_sale) */
$handler->display->display_options['fields']['field_point_of_sale_nid']['id'] = 'field_point_of_sale_nid';
$handler->display->display_options['fields']['field_point_of_sale_nid']['table'] = 'apachesolr_node_node_data_field_point_of_sale';
$handler->display->display_options['fields']['field_point_of_sale_nid']['field'] = 'field_point_of_sale_nid';
$handler->display->display_options['fields']['field_point_of_sale_nid']['label'] = 'Available at';
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_point_of_sale_nid']['element_wrapper_type'] = 'div';
$handler->display->display_options['fields']['field_point_of_sale_nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_point_of_sale_nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['link_to_node'] = 0;
$handler->display->display_options['fields']['field_point_of_sale_nid']['label_type'] = 'custom';
$handler->display->display_options['fields']['field_point_of_sale_nid']['multiple']['group'] = 1;
$handler->display->display_options['fields']['field_point_of_sale_nid']['multiple']['multiple_reversed'] = 0;
/* Sort criterion: Apache Solr: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'apachesolr_node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
/* Filter: Apache Solr: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'apachesolr_node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'producer_product' => 'producer_product',
);
/* Filter: Apache Solr: Search */
$handler->display->display_options['filters']['text']['id'] = 'text';
$handler->display->display_options['filters']['text']['table'] = 'apachesolr_node';
$handler->display->display_options['filters']['text']['field'] = 'text';
$handler->display->display_options['filters']['text']['exposed'] = TRUE;
$handler->display->display_options['filters']['text']['expose']['operator'] = 'text_op';
$handler->display->display_options['filters']['text']['expose']['limit_operators'] = array();
$handler->display->display_options['filters']['text']['expose']['label'] = 'Find a product:';
$handler->display->display_options['filters']['text']['expose']['identifier'] = 'text';
$handler->display->display_options['filters']['text']['expose']['single'] = TRUE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '7';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
$handler->display->display_options['path'] = 'local/food/test';

rjbrown99’s picture

#15 make sure you are using the 6.x-1.x-dev version from Feb 25, not the version in GIT. The GIT version is inconsistent with the master/Feb25 version and introduces regressions.

Also what do you mean by "default sorting" - the default is not to have anything in the sort field. In terms of click sorting, the patch in #8 seems to include an example of this on the title field. I would venture to say it's not supported in the main module at this point, without some additional patching.

rjbrown99’s picture

Hm, one thing I am noticing with my sort patch from #13: paged views show duplicates. IE:

1) View page one, see your nodes
2) Click pager to go to page 2
3) View page two, see nodes - but some of the nodes from page 1 may be here as well

It's random, so you never know where a node is going to show up. But it seems like follow-on pages should not show the same content as was previously displayed. Not sure how to tackle this one yet, I'm definitely open to ideas!

Scott Reynolds’s picture

Re: Paging and seeing duplicates
This will always be true and it is true of the SQL views as well. Really shouldn't be used for page views.

rjbrown99’s picture

After a bit more review of the duplicate issue, it's happening because each new page of the view calls the query() function again, and it re-runs the $seed so it comes up with a new random_123 number for each page. Per the Solr docs on randomization, as long as we call the same random_123 seed for each page, it will return the same random results. What this means to me is that if we can preserve the seed across pager page views, we can keep the same random order on each page and not show duplicates. Working on that now.

rjbrown99’s picture

This is interesting: views_random_seed module.

I think I like this the best though: session-based storage. You can hook the pager, determine what page you are on, and clear out the variable if you are on page 0. That would end up with a new randomized view each time, while allowing subsequent pages to not contain dupes.

Here's how I might clear it out...

function mymodule_views_pre_render(&$view) {
  $current_page = isset($view->query->pager->current_page) ? $view->query->pager->current_page : 0;
  if ($current_page == 0) {
    unset($_SESSION['apachesolr_views_random_sort_int']);
  }
}

There is very likely a better way to do that, but that's an initial idea.

rjbrown99’s picture

OK, so I think I'm finally done here. Ignore everything else I wrote before this post :)

There is a problem with $_SESSION and trying to clear it out on page 0. Views sort functions are applied after hook_views_pre_build() but before hook_views_post_build(). The challenge is that the current displayed page number (for a multi-page view output) is unknown on pre_build, still unknown when the sorts are applied, and then becomes known in post_build. What this means is that inside of the sort function you won't ever know if you are on page 0, 1, 2, or whatever, so there's no good way to clear out a page cache when you are on page 0.

This is very likely why the views_random_seed module folks implemented a time-based randomizer. It's the best you can do to minimize duplicates and still allow a fair degree of randomization. To that end, I am abandoning my own implementation of this and instead I created a patch for views_random_seed to enable it to work with Solr. In my testing, so far it's working quite well.

Here it is: #1262770: Support apachesolr_views module

TechNikh’s picture