I am trying to add OpenSearch functionality to my Yii application and have trouble configuring the UrlManager to route a search request to the right controller (called query in this case) and method (called index). The search works great if there are no white space in the search words. Whenever someone searches for more than one word, the UrlManager cannot find the controller and method to handle the search.
The url in the search.xml file that triggers the search is like this:
<Url type="text/html" template="[pathToMyApp]/application/index.php/query/{searchTerms}"/>
And my UrlManager is configured like this:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'<_c:(name|tag)>s/*' => '<_c>/index',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'query/suggest/<needle:\w+>'=>'query/suggest', // used to route OpenSearch JSON suggestions - works
'query/findbox'=>'query/findbox', // routes search queries from a form in the application - works
'query/<needle:\w+>'=>'query/index', // works only for search strings with no white space
),
'showScriptName' => true,
),
It seems that in
query/<needle:\w+>, the\w+part will stop matching at the first non-word char (e.g. a space). Changing the\wto something more forgiving (e.g.[\w ]) will probably do the trick.