Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • firepol 125 posts 173 karma points
    Oct 20, 2011 @ 20:46
    firepol
    0

    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);

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 21, 2011 @ 10:11
    Douglas Robar
    0

    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:

    Content
    - DE
    - - Suche
    - - blah blah
    - - yada yada
    - EN
    - - Search
    - - blah
    - - yada 

    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. 

  • firepol 125 posts 173 karma points
    Oct 21, 2011 @ 17:21
    firepol
    0

    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?

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 21, 2011 @ 21:10
    Douglas Robar
    0

    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. 

  • firepol 125 posts 173 karma points
    Oct 22, 2011 @ 18:21
    firepol
    0

    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

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 22, 2011 @ 19:38
    Douglas Robar
    0

    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. 

  • firepol 125 posts 173 karma points
    Oct 22, 2011 @ 22:48
    firepol
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft