Multi-Language Search Result page
Hi,
I'm using Structure to manage a multi-language site e.g.:
Home
Products
Services
About
de
- Products
- Services
- About
fr
- Products
- Services
- About
I'm new to Low Search so I'm experimenting but ideally I want to have:
domain.com/search/results
For all my English page results.
domain/com/de/search/results
For all my German page results etc.
However I don't have the different language entries in different channels. They're stored in the same channel(s) using the same Custom Fields for entry etc.
So my question is, how would I go about getting my desired behaviour working?
Thanks in advance.
Ryan
Replies
Ryan Taylor 10 Jan 2013 15:06
Additional.
I've experimented with created a channel purely for search result pages. And then adding that in on Structure and then create a page for English, a child page for German etc.
This results in my being:
domain.com/search/
and
domain.com/de/search/
Using entries gives me the added advantage of entering different language titles for the tops of the result pages.
This works for my English version. I have this for the search form:
Then I'm just using the example code to see if it works:
And as I say it does for the English version. For the German page:
domain.com/de/search/
I can visit that URL and it appears and shows "No search results" but as soon as there's a search parameter in the URL I get redirected to a 404.
I've tried changing the query parameter from {segment_2} to {segment_3} but that makes no difference.
Does anyone have any suggestions?
Thanks
Ryan
Low 10 Jan 2013 15:24
As for getting the right entries for the right language: you'll need a way to differentiate the entries in the same way that you would for a channel:entries tag. So, by custom field, status, channel, or something like that. Then you can tell Low Search to just return entries with custom_field="de" or status="de" etc.
Using Structure, the language is implied somewhere in the URI, which isn't searchable, so there's no way for Low Search to know which entry is in which language.
As for generating the actual results: Structure does away with the native URI logic, so you'll need something like Freebie to get to the original segment variables.
Check the template debugger for more info on what goes on behind the scenes.
Ryan Taylor 10 Jan 2013 15:55
Thanks for the reply. I've made good headway using Freebie. Now both English and German search results pages are working.
However I need to dynamically switch the result_page="" parameter on the {exp:low_search:form} tag but I'm having trouble.
I've written my own little plugin to determine the viewing language:
{exp:viewing_lang} this returns a language code.
So I want to set result_page="" to:
result_page="en/search"
result_page="de/search"
result_page="fr/search"
Depending on which language is being viewed.
I was trying to do this with PHP like so:
But is simply ignored and it ends up defaulting to search/results. If I echo I get what I expect:
result_page="en/search"
And ideas on how I can make this work?
Thanks
Ryan
Low 10 Jan 2013 15:58
Try not adding it as a tag parameter, but as a hidden input field instead:
Ryan Taylor 10 Jan 2013 16:07
Awesome. That worked perfectly!
My only issue now then is I need to switch the query="" parameter on the results page to use:
query="{freebie_2}"
for English pages and:
query="{freebie_3}"
for everything else...
Again I've tried doing a check with PHP but this doesn't work. Tried two approaches:
And also:
which results in a parsing error.
If you can answer this last problem, you'll officially be my new hero!
Ryan Taylor 10 Jan 2013 16:28
Hmm... I've found a work around though certainly not ideal:
Duplicating all the code just to change the parameter. But... it works. So unless you can suggest a better alternative. I'll roll with that for the time being.
Thanks for you help!
Low 11 Jan 2013 08:28
Your previous attempt won't work because of parse order. Advanced conditionals, PHP (on input or output) and tags... Not gonna work.
The attempt above will work, but both tags will be executed, which you might notice in the performance.
You might want to take a look at add-ons like Switchee or perhaps Stash to gain some performance there; but that's up to you.
Ryan Taylor 11 Jan 2013 09:34
Thanks for the tip! I'd not heard of Switchee. I'll use that. Thanks.