Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Apr 02, 2013 @ 17:03
    FarmFreshCode
    0

    Show TAGS in Search Results with a space after each comma

    I'm not sure how to adjust the output when using the TAG datatype. Right now my results after searching look like this:

    Title of Node
    Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana...

    which is causing some problems with my layout because the words never break in this scenario.

    I know I could solve this with some CSS and use: word-break:hyphenate; but I'd much rather have a space after the comma which would solve the problem too.

    Any thoughts? I'm still learning and could use as much detail in your answer if possible. Thanks!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 02, 2013 @ 18:16
    Douglas Robar
    1

    Unfortunately XSLT 1.0 doesn't have a built-in 'replace()' function for you to easily replace the "," with ", ". You can certainly do it and google is your friend to find resources such as http://stackoverflow.com/questions/3067113/xslt-string-replace.

    But this is a bother and I'd have to ask a more fundamental question that might resolve things very simply... do you really want to show the tag list in the search results? Surely you want to search within the tags but from my perspective it isn't relevant to display tags in the search results. Better would be to show the bodyText or other descriptive field.

    Remember, you can specify not only what fields XSLTsearch should look in, but also which fields should be used for displaying the results. I'd include the tags in the searchFields= parameter but not the previewFields= parameter. Then your problem is solved without modifying XSLTsearch at all.

    cheers,
    doug. 

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 02, 2013 @ 18:21
    Douglas Robar
    1

    I should mention that another option for doing a 'replace' if you decide to go down that road is to use the replace() function in the exslt:strings library, which is included with Umbraco.

    Or, you could use the umbraco.library:Replace() function.

    In any of these cases, I think you could replace all "," characters with the ", " string when sending the results to the screen and though it could add extra spaces in the html output the display would render with a single space because html only displays a single space to the screen no matter how much whitespace you have in the markup itself. You can use that to your advantage.

     

    Let us know what you decide and how you handle it, for the sake of the next fellow.

    cheers,
    doug. 

  • FarmFreshCode 225 posts 422 karma points
    Apr 02, 2013 @ 18:58
    FarmFreshCode
    0

    Hi Douglas,

    Thanks so much for your response.I really appreciate your time and guidance.

    To answer your first question... This search area is going to be used to find Research Interests of the Faculty. I was hoping to be able to create a bunch of nodes with the Faculty members name, and then allow them go wild with tags for themeselves. Using the TAG dataType would make it really easy for them to add in stuff like: criminal justice, police, policing, free speech.. ect. I really need it to be open to whatever they want to type in there and tags seemed like the best solution.

    Here's a graphic screenshot to illustrate the problem.

    Ok so I'm looking into the umbraco.library:Replace() function. But I'm not sure I know how to combine it in this case.. This works great hard coded ...

    <xsl:value-of select="umbraco.library:Replace('css,wordpress,swimming,travel,Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada', ',', ', ')"/>

    But I'm not sure how to replace my hard coded text with the value that actually calls the preview resuls.... (shown below)

    <xsl:value-of select="PS.XSLTsearch:surround(PS.XSLTsearch:escapingIntelligentSubstring($escapedData, 0, $previewChars), $search, $before, $after)" disable-output-escaping="yes"/>

     

     

  • FarmFreshCode 225 posts 422 karma points
    Apr 02, 2013 @ 21:04
    FarmFreshCode
    101

    Ok, well funny how you can come back from a meeting and everything just works super easy... anyway. So here is the code I'm using which works just GREAT!.... All I needed to do was overwrite the XSLT code:

    <xsl:value-ofselect="PS.XSLTsearch:surround(PS.XSLTsearch:escapingIntelligentSubstring($escapedData, 0, $previewChars), $search, $before, $after)"disable-output-escaping="yes"/>

    with....

    <xsl:value-of select="umbraco.library:Replace(PS.XSLTsearch:surround(PS.XSLTsearch:escapingIntelligentSubstring($escapedData, 0, $previewChars), $search, $before, $after), ',', ', ')" disable-output-escaping="yes"/>

    **Note that this is a special circumstance and I made my own XSLT file in order to prevent any of my modifications to the main XSLTsearch file. Just copied and pasted the XSLT data and applied the Macro Setting Options to my own version. But this allowed me to modify the results as I needed.

    Thanks Douglas Robar for pointing me in the right direction!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 02, 2013 @ 21:51
    Douglas Robar
    0

    Great stuff! Thanks for sharing your solution!

    cheers,
    doug. 

Please Sign in or register to post replies

Write your reply to:

Draft