I'm using XSLT search which works great apart from one thing. I have product nodes/pages where I have a search field property (used in XSLT search as a searchfield) called power, its a dropdown list with values from 0.4kW to 15kW the problem is, as an example when I check 5kW the returned results has 0.5kW ,1.5kW and the correct 5kW. All I want are all the 5kw is there a way to do this?
No, you are correct in what I mean. If that is not working, my best guess is the xsltSearch code must trim out the extra whitespace. Not sure how much digging that would require to change. Any XSLTSearch gurus around?
You are correct... XSLTsearch does a wildcard search for each term. Thus, 5kw will match 5kw, 0.5kw, 105kw, 55kwatts, etc. That's how XSLTsearch works. As you and Thomas also found, whitespace is removed from the outside of the search terms. Both of these behaviours is good for users, but not great in your scenario.
The solution is to modify the way XSLTsearch works. That's a benefit of the code being right in front of you. easy to modify if you need to.
To allow extra whitespace in the search term, modify the cleanSearchTerm() function in the /app_code/xsltsearch.cs file to allow it.
As for searching only full words, that's significantly more effort I'm afraid. It would primarily have to be changed in the xsltsearch.xslt file in the following template. In particular, you'd remove the 'contains()' function and look for an exact match. You'd need to update the fields being searched to have word boundaries so you could know where one field and the words/content in each field starts and ends. Not impossible but not trivial. The template is:
<xsl:templatename="booleanAndMatchedNodes">
Alternatively, you might hard-code some checks for specific fields and do an exact term match on those only, which would let the wildcard search (using 'contains()') work for most terms but not the dropdown list propertly.
I thought it would be quite easy to change. All I have is a search field property (selected from a dropdown when adding the value to the page) and want to just search for an exact string match of that property value eg 0.25kW not for eg. 0.25kw anywhere in the bodyText.
exact string match search
Hi,
I'm using XSLT search which works great apart from one thing. I have product nodes/pages where I have a search field property (used in XSLT search as a searchfield) called power, its a dropdown list with values from 0.4kW to 15kW the problem is, as an example when I check 5kW the returned results has 0.5kW ,1.5kW and the correct 5kW. All I want are all the 5kw is there a way to do this?
thank you
ian
You may want to modify your search phrase in this manner:
<space>5kW<space>
Basically, you are appending a space before and after the search term before performing the search.
hi,
thanks for the reply.
I have tried putting a ' ',   and %20 in the querystring but is still doesn't work. Do you mean change the xsltSearch code?
cheers
ian
No, you are correct in what I mean. If that is not working, my best guess is the xsltSearch code must trim out the extra whitespace. Not sure how much digging that would require to change. Any XSLTSearch gurus around?
Hi, Ian,
You are correct... XSLTsearch does a wildcard search for each term. Thus, 5kw will match 5kw, 0.5kw, 105kw, 55kwatts, etc. That's how XSLTsearch works. As you and Thomas also found, whitespace is removed from the outside of the search terms. Both of these behaviours is good for users, but not great in your scenario.
The solution is to modify the way XSLTsearch works. That's a benefit of the code being right in front of you. easy to modify if you need to.
To allow extra whitespace in the search term, modify the cleanSearchTerm() function in the /app_code/xsltsearch.cs file to allow it.
As for searching only full words, that's significantly more effort I'm afraid. It would primarily have to be changed in the xsltsearch.xslt file in the following template. In particular, you'd remove the 'contains()' function and look for an exact match. You'd need to update the fields being searched to have word boundaries so you could know where one field and the words/content in each field starts and ends. Not impossible but not trivial. The template is:
<xsl:template name="booleanAndMatchedNodes">
Alternatively, you might hard-code some checks for specific fields and do an exact term match on those only, which would let the wildcard search (using 'contains()') work for most terms but not the dropdown list propertly.
cheers,
doug.
hi doug,
thanks for your reply.
I thought it would be quite easy to change. All I have is a search field property (selected from a dropdown when adding the value to the page) and want to just search for an exact string match of that property value eg 0.25kW not for eg. 0.25kw anywhere in the bodyText.
thanks anyway
ian
is working on a reply...