Leveraging XSLT Search Package to Advance uComponents FilterNodes()
Hi -- this is a question for you, @DouglasRobar, or indeed anyone who is able to offer some assistance.
I am using the method ucomponents.xml:FilterNodes() for an Ajax resource library search screen on a site I'm working on. I've got a bunch of dropdowns which reflect various properties of the handful of Doctypes involved and also a "contains" field for a free text search within the current returned nodeset, etc. All is working fine. However...
Using the comparison between the user's text input and whatever text occurs in any nodenames or bodytext fields or metakeywords fields or whatever, I am only able to find EXACT matches of the string entered. In other words, I am only searching for "all of" the keywords entered, and in that order.
I noticed that the XSLT Search package, which I have always employed for my site-wide search in the header, is able to find "any of" the words entered by the user. I then studied the code as best I could, but I'm afraid I was not able to determine how this is being done, at least not to the extent of getting me started in any direction. I guess what I essentially need to do here is to "split" the words entered into the free text search field by a delimiter, in this case most likely a _space_, and to somehow work this into my FilterNodes() query, thus enabling the function to return documents that contain ANY OF the terms entered.
Anyone out there understand my predicament and have ideas on how I might be able to make my search functionality more advanced int his way?
I can offer up my current code but I'll wait for a reply first since this post is already probably too long to garner any attention!
Chriztian! Hey man. Thanks for replying. Here is bunch of existing (working) code -- I have bolded the areas I need to customize to allow for this inexact/flexible search:
<!-- run filter --> <xsl:variable name="filteredResources"> <xsl:choose> <xsl:when test="normalize-space(concat($contains, $type, $usecase, $industry, $product, $platform))"> <root> <xsl:copy-of select="ucomponents.xml:FilterNodes($currentPage, concat(' ancestor-or-self::Home[@isDoc]//Resources[1][@isDoc]/ResourceType [@isDoc][not(umbracoNaviHide=1)]//* [@isDoc][not(umbracoNaviHide=1)] [(name()="LeadProtectedFile" and normalize-space(resourceFile)) or (name()="LeadProtectedVideo" and normalize-space(embedCode))]', $filter))"/> </root> </xsl:when> <xsl:otherwise> <root> <xsl:copy-of select="$currentPage/ancestor-or-self::Home[@isDoc]//Resources[1]/ResourceType [@isDoc][not(umbracoNaviHide=1)]//* [@isDoc][not(umbracoNaviHide=1)] [(name()="LeadProtectedFile" and normalize-space(resourceFile)) or (name()="LeadProtectedVideo" and normalize-space(embedCode))]"/> </root> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- show results --> <xsl:choose> <!-- no filter; show featured items and latest 4 of each media type --> <xsl:when test="$filter = '[true()]'"> <!-- switch to default view macro --> <xsl:value-of select="umbraco.library:RenderMacroContent('<?UMBRACO_MACRO macroAlias="ResourceLibraryDefaultView" />', $currentPage/@id)" disable-output-escaping="yes" /> </xsl:when> <xsl:otherwise> <!-- filter has values; show search results --> </xsl:otherwise> </xsl:choose> </xsl:template>
Just not sure how to place any additional functions into this since I alerady have a concat() AND a contains() going on -- I had actually been trying to force lowercase on this comparison at an earlier stage of development and was unable to figure that out either. What I need is to compare the essentially tokenized ignore-case querystring value, with each of the comparison doctype properties indicated in the code, but so far it seems to have been beyond my skill level!
Hi Chriztian -- I totally figured that out based on your usual response time :) ENJOY your time off and I'll look forward to hearnig from you when you get a chance!
I really want to help you with this, but honestly, I'd have a C# developer write an extension for this after adding the third search parameter... XSLT is not good at complex string manipulation (which is effectively what you're doing here - and that's already one step removed from the actual problem (dynamic XPath)).
Still, it's possible to do it and I'd like to help you out - but I'll probably need to take it all apart and reassemble it - feel free to email me at (my firstname) @ (my lastname) .dk with maybe some links and the complete XSLT?
We can post the final results here when finished to close the thread properly.
Leveraging XSLT Search Package to Advance uComponents FilterNodes()
Hi -- this is a question for you, @DouglasRobar, or indeed anyone who is able to offer some assistance.
I am using the method ucomponents.xml:FilterNodes() for an Ajax resource library search screen on a site I'm working on. I've got a bunch of dropdowns which reflect various properties of the handful of Doctypes involved and also a "contains" field for a free text search within the current returned nodeset, etc. All is working fine. However...
Using the comparison between the user's text input and whatever text occurs in any nodenames or bodytext fields or metakeywords fields or whatever, I am only able to find EXACT matches of the string entered. In other words, I am only searching for "all of" the keywords entered, and in that order.
I noticed that the XSLT Search package, which I have always employed for my site-wide search in the header, is able to find "any of" the words entered by the user. I then studied the code as best I could, but I'm afraid I was not able to determine how this is being done, at least not to the extent of getting me started in any direction. I guess what I essentially need to do here is to "split" the words entered into the free text search field by a delimiter, in this case most likely a _space_, and to somehow work this into my FilterNodes() query, thus enabling the function to return documents that contain ANY OF the terms entered.
Anyone out there understand my predicament and have ideas on how I might be able to make my search functionality more advanced int his way?
I can offer up my current code but I'll wait for a reply first since this post is already probably too long to garner any attention!
Thanks Forum,
Garrett
Hi Garrett,
It doesn't sound too far-fetched to split the search term on spaces and then use contains() to look for ANY type matches.
Problem is how to best filter the results - various options, depending on how your tree looks, which nodes and properties to search...
Will gladly look at your code and provide tips for doing this
/Chriztian
Chriztian! Hey man. Thanks for replying. Here is bunch of existing (working) code -- I have bolded the areas I need to customize to allow for this inexact/flexible search:
Just not sure how to place any additional functions into this since I alerady have a concat() AND a contains() going on -- I had actually been trying to force lowercase on this comparison at an earlier stage of development and was unable to figure that out either. What I need is to compare the essentially tokenized ignore-case querystring value, with each of the comparison doctype properties indicated in the code, but so far it seems to have been beyond my skill level!
Thanks again in advance, @Chriztian.
Sincerely,
Garrett
Hi Chriztian -- hope my code didn't scare you away ;) Have you had a chance to look at my problem?
Thanks again,
Garrett
Hi Garrett,
Not scared - overwhelmed maybe, but most of all on vacation :-)
Will have a look soon!
/Chriztian
Hi Chriztian -- I totally figured that out based on your usual response time :) ENJOY your time off and I'll look forward to hearnig from you when you get a chance!
//Garrett
Hi Chiztian - wondering if you have had a chance to take a look at this yet? I'm still stuck on it.
Thanks again,
Garrett
Bumping this post again - still need help on this if anyone can hear me!
//Garrett
Hi Garrett,
I really want to help you with this, but honestly, I'd have a C# developer write an extension for this after adding the third search parameter... XSLT is not good at complex string manipulation (which is effectively what you're doing here - and that's already one step removed from the actual problem (dynamic XPath)).
Still, it's possible to do it and I'd like to help you out - but I'll probably need to take it all apart and reassemble it - feel free to email me at (my firstname) @ (my lastname) .dk with maybe some links and the complete XSLT?
We can post the final results here when finished to close the thread properly.
/Chriztian
is working on a reply...