-
- 143 Posts
Hello fellow MODx users and developers
I just ran into a problem with the AjaxSearch Snippet I could not solve by myself and also didn’t find any solution in the forums:
I have a multilingual website and want to limit the search results to the currently selected language. Is there any possibility to tell the AjaxSearch snippet to search down only a specific document, like we have the &startId in Ditto and Wayfinder?
Thanks for your help!
Bogdan
-
- 956 Posts
In assets/snippets/AjaxSearch/AjaxSearch.inc.php, there’s line 158 with:
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;";
You could add another filter here at the end of the query. Of course, then you would have to duplicate the snippet for every language, because the setting would be hard-coded.
e.g.
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0 AND sc.parent=5;"; // only search docs within folder id 5
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0 AND sc.parent=100;"; // only search docs within folder id 100
Changing the code to accept one more paramenter (e.g. &restrictToParent=`100`) wouldn’t be that hard I guess...
-
- 143 Posts
Hello Ganesh,
thanks for the hint I could indeed solve my problem and even managed to ad a $startId snippet parameter - hurray
I think it would be nice and useful to have this additional parameter build in the next version of AjaxSearch. I’ll send the link of this post to Kyle Jaebker, maybe he will consider it.
Thanks again
Bogdan
-
- 1 Posts
I would actually like to be able to search a specific group of ID’s. That way I could limit the search to my faq’s section.
-John Blair (KoX)
-
- 956 Posts
Well, if your FAQ docs are all in one folder, the above suggestion should work fine. Did you try it?
-
- 40 Posts
The approach suggested limits to only documents with a shared parent. I use nested documents to categorize products, so it wasn’t finding any.
Then I got the idea to have it filter documents by template type. All my products have a template "Product Detail" with id 10, so by modifying this line in AjaxSearch.inc.php
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;";
to
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0 AND sc.template=10;";
However I couldn’t get it to work. Any Suggestions?