Hi,

I have a finder set up to filter a content type on a number of fields. It works, but if any of the options on the finder form are left empty (which I want to be taken as meaning do not filter by this field) then I get duplicate results showing.

As a workaround, for the moment I have changed my view to only show distinct results but Views warn that this makes the query very slow, and sure enough it is VERY slow.

I guess there is some logic I am missing to prevent duplicates showing up to begin with. Any guidance on how to correctly configure the options to achieve this would be much appreciated.

Jono

$finder = new finder;
$finder->disabled = FALSE; /* Edit this to true to make a default finder disabled initially */
$finder->api_version = 2;
$finder->name = 'windsurf_sail_search';
$finder->views_view = 'windsurf_sails';
$finder->views_display = 'page';
$finder->title = 'Windsurf sail search';
$finder->description = '';
$finder->path = 'windsurf/sail-search';
$finder->block = TRUE;
$finder->status = TRUE;
$finder->settings = array(
  'block' => TRUE,
  'form_on_page' => 0,
  'find_button' => TRUE,
  'find_text' => 'Find',
  'go_text' => 'Go',
  'ajax_effect' => 'slide',
  'show_results' => 'filter',
  'results_style' => 'views',
  'no_results' => 'default',
  'pager' => '0',
  'redirect' => 'never',
  'element_logic' => 'AND',
  'url' => 'enabled',
  'url_delimiter' => ',',
  'ajax' => 0,
  'ajax_remote' => 0,
);
$finder->elements = array(
  'size_from' => (object) array(
    'id' => 'size_from',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'AND',
      'match' => 'gte',
      'fields' => array(
        'field_data_field_wssailsize.field_wssailsize_value' => (object) array(
          'table' => 'field_data_field_wssailsize',
          'field' => 'field_wssailsize_value',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'match_custom_operator' => '',
      'match_custom_prefix' => '',
      'match_custom_suffix' => '',
      'default_value' => '0',
      'size' => '4',
    ),
    'weight' => '-6',
    'title' => 'min',
    'element' => 'text',
  ),
  'to' => (object) array(
    'id' => 'to',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'AND',
      'match' => 'lte',
      'match_custom_operator' => '',
      'match_custom_prefix' => '',
      'match_custom_suffix' => '',
      'fields' => array(
        'field_data_field_wssailsize.field_wssailsize_value' => (object) array(
          'table' => 'field_data_field_wssailsize',
          'field' => 'field_wssailsize_value',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'default_value' => '15',
      'size' => '4',
    ),
    'weight' => '-5',
    'title' => 'max',
    'element' => 'text',
  ),
  'terms' => (object) array(
    'id' => 'terms',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'AND',
      'match' => 'e',
      'fields' => array(
        'taxonomy_term_data_6.name' => (object) array(
          'table' => 'taxonomy_term_data_6',
          'field' => 'name',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'default_value' => '',
      'empty' => 'prepend',
      'empty_text' => '<all models>',
      'title_display' => 'invisible',
      'required' => 0,
    ),
    'weight' => '-4',
    'title' => 'model',
    'element' => 'select',
  ),
  'brand' => (object) array(
    'id' => 'brand',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'AND',
      'match' => 'e',
      'fields' => array(
        'taxonomy_term_data_7.name' => (object) array(
          'table' => 'taxonomy_term_data_7',
          'field' => 'name',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'multiple' => 0,
      'empty' => 'prepend',
      'empty_text' => '<all brands>',
      'title_display' => 'invisible',
      'default_value' => '',
    ),
    'weight' => '-3',
    'title' => 'Brand',
    'element' => 'select',
  ),
  'location' => (object) array(
    'id' => 'location',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'OR',
      'match' => 'e',
      'fields' => array(
        'field_data_field_wssaillocation.field_wssaillocation_value' => (object) array(
          'table' => 'field_data_field_wssaillocation',
          'field' => 'field_wssaillocation_value',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'default_value' => '',
      'multiple' => 1,
      'empty' => 'prepend',
      'empty_text' => '<all locations>',
      'title_display' => 'before',
      'match_custom_operator' => '',
      'match_custom_prefix' => '',
      'match_custom_suffix' => '',
    ),
    'weight' => '-2',
    'title' => 'location',
    'element' => 'select',
  ),
  'status' => (object) array(
    'id' => 'status',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'OR',
      'match' => 'e',
      'fields' => array(
        'field_data_field_wssailstatus.field_wssailstatus_value' => (object) array(
          'table' => 'field_data_field_wssailstatus',
          'field' => 'field_wssailstatus_value',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'multiple' => 1,
      'empty' => 'prepend',
      'empty_text' => '<any status>',
    ),
    'weight' => '0',
    'title' => 'status',
    'element' => 'select',
  ),
  'hide_dead' => (object) array(
    'id' => 'hide_dead',
    'finder' => 'windsurf_sail_search',
    'settings' => array(
      'field_logic' => 'AND',
      'value_logic' => 'OR',
      'match' => 'ne',
      'fields' => array(
        'field_data_field_wssailstatus.field_wssailstatus_value' => (object) array(
          'table' => 'field_data_field_wssailstatus',
          'field' => 'field_wssailstatus_value',
          'relationship' => NULL,
          'format' => 'filter_xss',
        ),
      ),
      'default_value' => 'DEAD',
      'match_custom_operator' => '',
      'match_custom_prefix' => '',
      'match_custom_suffix' => '',
      'empty' => 'prepend',
      'empty_text' => '<exclude none>',
      'multiple' => 1,
    ),
    'weight' => '0',
    'title' => 'exclude if status =',
    'element' => 'select',
  ),
);

Comments

danielb’s picture

Setting the View to distinct is the only way I know. When you're dealing with multiple taxonomy terms then you will get duplicate records because of the design of the taxonomy tables.

It *may* be possible to improve the performance of finder_build_display_query() in build.inc by not always joining tables if there is some reason they shouldn't be. I'll look into it, but no guarantees.
That whole block of code within foreach (array_values($keyword_array) as $keyword_position => $keyword) { ... } could be skipped when ($keyword !== '' && $keyword !== NULL && $mode == 'results') or rather only executed when the opposite of all that is TRUE.
There might be a similar saving possible for the 'choices' queries, though adding every table and checking every field for 'NOT NULL' seems to be a bloody good idea, so maybe not.
I haven't really thought any of this through too much but I'd better get my thoughts down to revise later.

jonodunnett’s picture

OK, thanks for looking...
I guess I can live with slow but I thought maybe there was an easy fix to avoid duplicates. Do you mean that if I used field data in place of taxonomy term data then I wouldn't have the problem of duplicates in the first place? Would doing this be likely to speed up the query much?

danielb’s picture

If you want to investigate a quick way would be to install 'computed field' and simply have it copy the value of the taxonomy terms. (The searchable value, not the machine-readable value.)

danielb’s picture

Status: Active » Closed (won't fix)

thread over