I do that because I want to specify a different "source" node, depending on the culture... (I have a multilanguage site):
Don't know if it's a bug or not, so I ask "how to", my problem is the "resultsPerPage" if I use the code behind way, the results are always still only 5.
If I put the macro in the .master page (so not in the code behind) it works well.
Any ideas? Thank you. --firepol
Here my code:
mcr.Alias = "XSLTsearch";
switch (this.Page.Language) { case "de": mcr.MacroAttributes.Add("source", "1030"); break; case "en": mcr.MacroAttributes.Add("source", "1031"); break; default: break; }
You shouldn't need to go about it this way... XSLTsearch is already multi-site and multi-language aware. Here's how I'd go about it...
1. Either use the default XSLTsearch template or make your own. Put the XSLTsearch macro on it... but leave the source= parameter EMPTY (it will appear as source="" after you insert the macro). Set any other properties you want to your preferred settings.
2. Create a search page for each language of your site. They will all use the same template to display results.
3. Assign a language to each part of the site using the 'Manage Hostnames' feature. Be sure to do this for all your top level nodes (DE, EN, etc.); don't leave any unset. (The rule is, if you set one, set them all)
4. Update the dictionary keys for the various XSLTsearch fields to include German alternatives
5. Searching from the English search page will return results in English from within the EN site. Searching from the German suche page will return results in German only from within the DE site.
I already had 2 separtate search pages for each one of my languages...
I configured the hostnames: node "de" -> domain: localhost/de, node "en": domain: localhost/en. I republished the site. I left source = "". It finds mixed results... (in both languages de and en...)... ideas?
If you're finding results from both sites then I wonder if you modified the xsltsearch.xslt to use the GetXmlAll() feature as is sometimes recommended on the forum. You should leave the xsltsearch.xslt file in its original condition, which will search only within the current search page's section of the site.
I didn't modify that much the original xslt, so in the end to make it work I just added some "IF" in the masterpage and modified the source accordingly.
Ah, another question. Is it possible to exlude some document types from the search? I have some document types without template (because they are childs of a parent page/container, which has a template that loops and shows them all already), that can lead to problems...
Odd, it should have "just worked" but I'm glad you got it sorted out.
As for excluding things... do that where the $possibleNodes variable is set. Just add more conditions to check for various nodeTypeAlias's you don't want.
As for searching on a container page, you can handle that in one of two ways. Either modify XSLTsearch.xslt to display and link to the parent document. Personally not too excited about that approach since it could mean seeing the same container document in the results multiple times in some cases. Instaed, I'd leave the xslt alone and add a template to the 'child' documents that does a redirect to the parent page when clicked. That way you'd see a result for the specific event, staff person, news item, faq, or whatever it is but when the result were clicked it would actually send the visitor to the containing parent page.
There are some forum posts on how to do this. It's all really simple actually.
About the possible nodes, I'll have a look at it. About the template to the childs, actually I already have it and it's already a redirect ;)
The problem of the redirect, is when the user clicks on "back" he won't go back to the search results, but back to the child, which is a redirect, so basically the "back" won't work as expected (from the user point of view)...
But I'll sort these things out in a way or another. Thanks again for your precius feedback. I really appreciate your kind support.
programmatically add xsltsearch to master page
Hi, I try to programmatically add xsltsearch in my master page, as explained here:
http://our.umbraco.org/forum/developers/api-questions/7123-Pass-public-variable-in-MasterPage-to-User-Control-Macro
I do that because I want to specify a different "source" node, depending on the culture... (I have a multilanguage site):
Don't know if it's a bug or not, so I ask "how to", my problem is the "resultsPerPage" if I use the code behind way, the results are always still only 5.
If I put the macro in the .master page (so not in the code behind) it works well.
Any ideas? Thank you. --firepol
Here my code:
mcr.Alias = "XSLTsearch";
switch (this.Page.Language)
{
case "de":
mcr.MacroAttributes.Add("source", "1030");
break;
case "en":
mcr.MacroAttributes.Add("source", "1031");
break;
default:
break;
}
mcr.MacroAttributes.Add("searchFields", "metaKeywords,headline,title,metaDescription,content");
mcr.MacroAttributes.Add("previewFields", "content");
mcr.MacroAttributes.Add("previewChars", "145");
mcr.MacroAttributes.Add("resultsPerPage", "50");
mcr.MacroAttributes.Add("showOrdinals", "0");
mcr.MacroAttributes.Add("showScores", "0");
this.searchMacroContainer.Controls.Add(mcr);
You shouldn't need to go about it this way... XSLTsearch is already multi-site and multi-language aware. Here's how I'd go about it...
1. Either use the default XSLTsearch template or make your own. Put the XSLTsearch macro on it... but leave the source= parameter EMPTY (it will appear as source="" after you insert the macro). Set any other properties you want to your preferred settings.
2. Create a search page for each language of your site. They will all use the same template to display results.
Your content tree would look like this:
3. Assign a language to each part of the site using the 'Manage Hostnames' feature. Be sure to do this for all your top level nodes (DE, EN, etc.); don't leave any unset. (The rule is, if you set one, set them all)
4. Update the dictionary keys for the various XSLTsearch fields to include German alternatives
5. Searching from the English search page will return results in English from within the EN site. Searching from the German suche page will return results in German only from within the DE site.
That's all there is to it!
cheers,
doug.
Hi Doug,
I already had 2 separtate search pages for each one of my languages...
I configured the hostnames: node "de" -> domain: localhost/de, node "en": domain: localhost/en. I republished the site. I left source = "". It finds mixed results... (in both languages de and en...)... ideas?
If you're finding results from both sites then I wonder if you modified the xsltsearch.xslt to use the GetXmlAll() feature as is sometimes recommended on the forum. You should leave the xsltsearch.xslt file in its original condition, which will search only within the current search page's section of the site.
Here's a more detailed description of setting up XSLTsearch for us in multilingual sites: http://blog.percipientstudios.com/2010/11/17/quick-and-easy-multi-lingual-search-pages-for-umbraco-sites.aspx
cheers,
doug.
Hi Doug,
I didn't modify that much the original xslt, so in the end to make it work I just added some "IF" in the masterpage and modified the source accordingly.
Ah, another question. Is it possible to exlude some document types from the search? I have some document types without template (because they are childs of a parent page/container, which has a template that loops and shows them all already), that can lead to problems...
Thanks mate, cheers
Odd, it should have "just worked" but I'm glad you got it sorted out.
As for excluding things... do that where the $possibleNodes variable is set. Just add more conditions to check for various nodeTypeAlias's you don't want.
As for searching on a container page, you can handle that in one of two ways. Either modify XSLTsearch.xslt to display and link to the parent document. Personally not too excited about that approach since it could mean seeing the same container document in the results multiple times in some cases. Instaed, I'd leave the xslt alone and add a template to the 'child' documents that does a redirect to the parent page when clicked. That way you'd see a result for the specific event, staff person, news item, faq, or whatever it is but when the result were clicked it would actually send the visitor to the containing parent page.
There are some forum posts on how to do this. It's all really simple actually.
cheers,
doug.
About the possible nodes, I'll have a look at it. About the template to the childs, actually I already have it and it's already a redirect ;)
The problem of the redirect, is when the user clicks on "back" he won't go back to the search results, but back to the child, which is a redirect, so basically the "back" won't work as expected (from the user point of view)...
But I'll sort these things out in a way or another. Thanks again for your precius feedback. I really appreciate your kind support.
Cheers
is working on a reply...