Hello

Now the sphinxsearch module correctly handles only multi-select and tagged vocabularies. It's because single-valued selects passing their values not as
[terms1] => ( [1] => 1 )

but as
[terms1] => 1

In this case we are validating the form, our sphinxsearch_parse_request() tracts this value as passed from GET (as you remember, our GET contains string values for taxonomies). It tries to load term with name "1" and of course, it fails.

My resolution was to provide a vay to sphinxsearch_parse_request() function to know what it doing right now — parsing GET or validating the form. And to make corresponding handling of the cases. And finally — all sarted to works fine.

Please, review changes. Thanks.

Comments

neochief’s picture

StatusFileSize
new2.83 KB

fixed some typos in comments :)

markus_petrux’s picture

hmm... are you altering the advanced search form? AFAIK, form elements related to taxonomy are built with #multiple attribute enabled in this module, so that's why single-select elements weren't resolved within the request parsing code. So the problem seems to affect also the way the form elements are generated.

I woud like to mention that the way the advanced search form is generated is going to be rewritten with hook_sphinxsearch_api() in mind, and as described here (point 2 below "where do we go?" sentence). It will change because I wish to provide a method to configure which options will be enabled for the advanced search form, and also how those options should be applied to search query filters (AND?, OR?). And that will affect the way form elements are built (single-select vs. multi-select), so it makes sense to code the request parser to differentiate what is generated on submit in each case, etc.

Tha being said, I would not add another argument to sphinxsearch_parse_request(). Maybe extending the information stored in $request_options with an element '#method' that can be set to the value 'post' from the submit handler of the search page (the request parser could then assume 'get' if '#method' is not present).

markus_petrux’s picture

Status: Needs review » Needs work
neochief’s picture

Yes, I'm altering the form manually, because at this time there are no better way to do needed things. I understand that my changes can be erased by your rewrite, but I have no other way but to write code right now, because of my project's terms. By the way, my series of patches is ending right here, because, it seems that I've complete a working search at my project. So, I just want to thank you, Markus, for the great job you done with this module.

PS. I'll help you fixing the bugs when you'll complete rewriting the API :p
P.P.S. Take a look that I've made

markus_petrux’s picture

Looks great, and thanks for the compliments.

In the meantime, here's another alternative that will allow you to implement your changes with no need to patch the sphinxsearch_parse_request() function.

/**
 * Implementation of hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'sphinxsearch_search_form') {
    // Here you can alter the taxonomy form elements...

    // Now, you can add your validate handler to execute first in the chain.
    array_unshift($form['#validate'], 'mymodule_search_form_validate');
  }
}

/**
 * Validate the advanced search form.
 *
 * Use this to alter the format of taxonomy elements of type single-select
 * to a format that can be processed by sphinxsearch_parse_request().
 */
function mymodule_search_form_validate($form, &$form_state) {
  // For all taxonomy elements defined in the form...
  foreach ($form['advanced']['taxonomy'] as $key => $element) {
    // Search taxonomy elements of type single-select.
    if (substr($key, 0, 5) == 'terms' && !$element['#multiple']) {
      // Transform the submitted value into an array.
      $form_state['values'][$key] = array($form_state['values'][$key] => $form_state['values'][$key]);
    }
  }
}
neochief’s picture

Actually I've tried to do such thing, but my validator was executed only after sphinxsearch's validator. But with array_unshift trick it can be really possible. Thanks for good idea!

neochief’s picture

Status: Needs work » Closed (fixed)