I'm currently thinking about what would be the best way to go about using XSLTsearch for showing two different search results on the same page.
I have 1 search field and I need to display two search result on the same page based on the input.
So I'm going to have results from a content section and a news section displayed. You can see what the result should be by looking at http://www.sinodanishcenter.dk/index.php?menu_id=8 and search for "news" for instance.
I need to achieve the same thing.
Currently I have added a parameter to the XSLTsearch macro so I'm able to select the source of the news. Now I need to figure out how this is done most easily so I'm hoping for some input and guidelines for this :)
Couldn't you put the search macro on the template twice, with different parameters (for the source and also for any fields to search within unique to each section)?
My only concern is that one of the sources is the siteroot and the other is located as a child of the siteroot. Like this...
Home - document - document - news document - document - etc.
So in the case where my source is Home i don't want it to output the results for news document and it's children as well in the result. Guess I can make some comparison in XSLT to make sure that it's not included if the source is "Home".
I will look further into it, thanks for the input so far.
Yeah, I'd still use two macros. But perhaps duplicate the xsltsearch macro and .xslt file and modify one of them to exclude news items. Here's an old (aka, legacy xml schema) discussion on how to do that. The logic is the same in XSLTsearch v3 but you'll want to use the new xpath to achieve the same results. It's just a minor customization to ignore certain docTypes.
I have installed CWS Starter site with the XSLTSearch and I am now attempting to restrict the search to just the News and Events Section of the site by specifying the node types it should search. The blog linked above is very clear, however the changes suggested there didn't work for me. It is ignoring the restriction of the node type and searching everything.
I also noticed that variables aside, there was a slight difference in the example code and the actual code. This may due to XSLTSearch version changing between the blog and now.
This is the restricting code I'm using in the XSLT file is;
You've got the correct idea but the wrong XML syntax (the blog post was for the legacy xml schema in Umbraco). What you should have for the new schema is:
<xsl:variable name="possibleNodes" select="$items/descendant-or-self::*[
@isDoc
and (
name() = 'CWS_NewsItem'
or name() = 'CWS_EventItem'
)
and string(umbracoNaviHide) != '1'
and count(attribute::id)=1
and (umbraco.library:IsProtected(@id, @path) = false()
or umbraco.library:HasAccess(@id, @path) = true())
]"/>
Thanks for this and the swift response. I'm afraid though, it's still not confining the results to the nodes/doc-types I'm looking for.
Although I'm quite happy editing existing files I haven't been trained in Visual Studio or WebMatrix so I'm not sure if I have done everything that is necessary to make the changes take effect.
Is there anything else I have to do other than edit the XSLT and save it?
Just edit the xslt and save it, that's all that's necessary. And that can be done directly inside Umbraco so no particular need for WebMatrix or Visual Studio for this.
The above modification will only return pages with a document type of CWS_NewsItem or CWS_EventItem. Do be sure those are the alias names associated with the document types you want to return results from. The simple way to do this is:
In the Content section of umbraco, select a page you want XSLTsearch to search.
Click the 'Properties' tab and you'll see the document type listed. Note this doctype.
In the Settings section of umbraco, expand the document types tree and select the document type you noted above.
On the 'Info' tab you'll see the Name and Alias fields. You want the Alias.
Enter the Alias for the document type on the name()='mydoctypealias' line in the XSLT.
If you have multiple document types you want to search, use an 'and' as I've shown above.
Thanks, I've checked those things and they are as you instructed.
It's interesting that you say I should be able to access XSLTsearch.xslt from within Umbraco as it's not in the list. This search came as part of the CWS Starter Site and the XSLTsearch.xslt file doesn't appear in the list of xslt files in the developer's section. I understood it was the XSLTsearch but maybe it's not.
I have another umbraco site that you sent me a few weeks back where XSLTsearch was installed on a blog site and here the XSLTsearch.xslt file appears in the list of xslt files in the developer's section. I'm really quite puzzled.
This might more appropriately be a question for the CWS forum instead. But let's try a bit more anyway.
Depending on which version of CWS you installed you'll have either XSLTsearch or Examine as the search engine. They are very different and could explain why you don't see XSLTsearch (in the XSLT tree of the Developer section of the Umbraco interface).
How to show two different search results
Hi guys
I'm currently thinking about what would be the best way to go about using XSLTsearch for showing two different search results on the same page.
I have 1 search field and I need to display two search result on the same page based on the input.
So I'm going to have results from a content section and a news section displayed. You can see what the result should be by looking at http://www.sinodanishcenter.dk/index.php?menu_id=8 and search for "news" for instance.
I need to achieve the same thing.
Currently I have added a parameter to the XSLTsearch macro so I'm able to select the source of the news. Now I need to figure out how this is done most easily so I'm hoping for some input and guidelines for this :)
Thanks.
/Jan
Couldn't you put the search macro on the template twice, with different parameters (for the source and also for any fields to search within unique to each section)?
cheers,
doug.
Hi Doug
Hmm yeah I suppose that could work actually.
My only concern is that one of the sources is the siteroot and the other is located as a child of the siteroot. Like this...
Home
- document
- document
- news document
- document
- etc.
So in the case where my source is Home i don't want it to output the results for news document and it's children as well in the result. Guess I can make some comparison in XSLT to make sure that it's not included if the source is "Home".
I will look further into it, thanks for the input so far.
/Jan
Yeah, I'd still use two macros. But perhaps duplicate the xsltsearch macro and .xslt file and modify one of them to exclude news items. Here's an old (aka, legacy xml schema) discussion on how to do that. The logic is the same in XSLTsearch v3 but you'll want to use the new xpath to achieve the same results. It's just a minor customization to ignore certain docTypes.
http://blog.percipientstudios.com/2009/4/7/customizing-xsltsearch.aspx
cheers,
doug.
Hi Doug
Thank you very much - I should be able to finish the job from here :)
/Jan
I have installed CWS Starter site with the XSLTSearch and I am now attempting to restrict the search to just the News and Events Section of the site by specifying the node types it should search. The blog linked above is very clear, however the changes suggested there didn't work for me. It is ignoring the restriction of the node type and searching everything.
I also noticed that variables aside, there was a slight difference in the example code and the actual code. This may due to XSLTSearch version changing between the blog and now.
This is the restricting code I'm using in the XSLT file is;
<xsl:variable name="possibleNodes" select="$items/descendant-or-self::node[
string(data [@alias='umbracoNaviHide']) != '1'
and (
@nodeTypeAlias = 'CWS_NewsItem'
or @nodeTypeAlias = 'CWS_EventItem'
)
and count(attribute::id)=1
and (umbraco.library:IsProtected(@id, @path) = false()
or umbraco.library:HasAccess(@id, @path) = true())
]"/>
What should my next steps be?
Gus
Hi, Gus,
You've got the correct idea but the wrong XML syntax (the blog post was for the legacy xml schema in Umbraco). What you should have for the new schema is:
cheers,
doug.
Thanks for this and the swift response. I'm afraid though, it's still not confining the results to the nodes/doc-types I'm looking for.
Although I'm quite happy editing existing files I haven't been trained in Visual Studio or WebMatrix so I'm not sure if I have done everything that is necessary to make the changes take effect.
Is there anything else I have to do other than edit the XSLT and save it?
Thanks
Gus
Just edit the xslt and save it, that's all that's necessary. And that can be done directly inside Umbraco so no particular need for WebMatrix or Visual Studio for this.
The above modification will only return pages with a document type of CWS_NewsItem or CWS_EventItem. Do be sure those are the alias names associated with the document types you want to return results from. The simple way to do this is:
cheers,
doug.
Thanks, I've checked those things and they are as you instructed.
It's interesting that you say I should be able to access XSLTsearch.xslt from within Umbraco as it's not in the list. This search came as part of the CWS Starter Site and the XSLTsearch.xslt file doesn't appear in the list of xslt files in the developer's section. I understood it was the XSLTsearch but maybe it's not.
I have another umbraco site that you sent me a few weeks back where XSLTsearch was installed on a blog site and here the XSLTsearch.xslt file appears in the list of xslt files in the developer's section. I'm really quite puzzled.
Thanks
Gus/Andrew
Hey Gus (or is it Andrew?)
This might more appropriately be a question for the CWS forum instead. But let's try a bit more anyway.
Depending on which version of CWS you installed you'll have either XSLTsearch or Examine as the search engine. They are very different and could explain why you don't see XSLTsearch (in the XSLT tree of the Developer section of the Umbraco interface).
CWS 2.x uses XSLTsearch (and XSLT macros)
CWS 3.x uses Examine (and Razor macros)
Which one did you install?
cheers,
doug.
Ah that'll be it then. I've installed CWS 3.0.2 which explains everything. It wasn't clear to me from the documentation that XSLT was no longer used.
Thank you for your explanations and patience, I'll have to try a different route to set it up.
Thanks
Cheers
Andrew/Gus
is working on a reply...