:)

What is the easiest way to change search parameter name?

I mean: I want to replace the previous search engine with Sphinx. The previous search parameter was 'q' (like domain.com/search?q=term).

Now, how should I rewrite it to the present 'keys'? Maybe 'keys' could be configurable value?

Thanks,
Szy.

Comments

szy’s picture

Status: Closed (fixed) » Active

... 'rewrite it' - I mean rewrite all previous urls using 'q', remembered
by search engines, bookmarks, etc., to make them working again
with new search index.

Szy.

markus_petrux’s picture

At one point I'm planning to implement hook in different places to allow external modules change the behaviour of the sphinxsearch module, but I'm not ready for that yet, as I first would like to add a couple more features (cache sphinx query results and maybe some kind of access control mechanism).

I you need this feature now, then you would have to patch sphinxsearch.common.inc. However, you cannot use 'q' as it is the query string argument used by Drupal for the site path that is passed to Drupal index.php.

Anyway, here's an example on how 'keys' could turned into 'query':

- Function sphinxsearch_get_query_string: Adding something like this before the return statement

if (isset($query['keys'])) {
  $query['query'] = $query['keys'];
  unset($query['keys']);
}

- Function sphinxsearch_parse_request: Adding something like this just after definition of the $search_options array on top of the funcion:

if (isset($request_options['query'])) {
  $request_options['keys'] = $request_options['query'];
  unset($request_options['query']);
}

However, with those hooks that I'm planning to add in the module, it will be possible for external modules to extend the number of fields indexed, available for advanced search form, faceted search, etc. So if you change the name of query string variables now, those may conflict with other fields added by external modules in the future. ie. the query string used for seaches imposes a single namespace for variables, where collissions are possible and will generate unexpected results.

I'm posting a possible alternative for you with the above example, but you should take care to maintain it, if conflicts occur in the future. ;)

szy’s picture

Status: Active » Closed (fixed)

Your support is great, thanks, works just like I wanted it.

Szy.

Status: Active » Closed (fixed)