Copied to clipboard

Flag this post as spam?

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


  • ian 35 posts 135 karma points
    May 17, 2013 @ 15:47
    ian
    0

    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

     

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 16:34
    Thomas Brinegar
    0

    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.

  • ian 35 posts 135 karma points
    May 17, 2013 @ 17:07
    ian
    0

    hi,

    thanks for the reply.

    I have tried putting a ' ', &nbsp and %20 in the querystring but is still doesn't work. Do you mean change the xsltSearch code?

     

    cheers

     

    ian

  • Thomas Brinegar 84 posts 162 karma points
    May 17, 2013 @ 17:14
    Thomas Brinegar
    0

    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?

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    May 17, 2013 @ 18:32
    Douglas Robar
    0

    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. 

  • ian 35 posts 135 karma points
    May 20, 2013 @ 12:45
    ian
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft