Copied to clipboard

Flag this post as spam?

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


  • John Halsey 59 posts 220 karma points
    Jun 19, 2013 @ 12:52
    John Halsey
    0

    Node() wildcard only matching one element on page

    Hello,

    I'm developing a product website.  I'm trying to impliment a seach feature where the end user can type in a word or phrase, and then my xslt user control will seach all the elements of all the 'Product' nodes and bring back all the matches.

    I have read up on wildcards and think that node() does everything I want it to, but it's only searching in one element of the page, and as it happens it is the first element (Meta page title) that appears.

    Is there a way I can search all the elements?

    Here is my code:

    <!-- get the value from the input text box -->
    <xsl:variable name="textBoxValue" select="umbraco.library:Request('searchBox')"/>
    <!-- create looping variable that seaches all products with the search term -->
    <xsl:variable name="loop" select="$currentPage/Product[node() = contains(node(),$textBoxValue)]"/>
    <xsl:for-each select="$loop [@isDoc and string(umbracoNaviHide) != '1']">
    <div class="productListDiv">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:if test="mainImage &gt; 0">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(mainImage, false())" />
    <img src="{$mediaNode/umbracoFile}"
    width="100" class="productImage" alt="{$mediaNode/altText}" />
    </xsl:if>
    <h3>
    <xsl:value-of select="brand"/>&nbsp;<xsl:value-of select="productTitle"/>
    </h3>
    </a>
    <p>
    <xsl:value-of select="shortDescription"/>
    </p>
    <div class="clearing"></div>
    </li>
    </div>
    </xsl:for-each> 

    When I enter a word into the text box (and I know I need to think about case sensitivity), it is only bringing back the products that have that word in the meta page title.  

    I have other elements in the Product node that I want it to seach like brand, productTitle, shortDescription, longDescription... etc.

    Any ideas / suggestions?

    Many Thanks

    John

  • John Halsey 59 posts 220 karma points
    Jun 19, 2013 @ 16:14
    John Halsey
    0

    I think I worked out a way of doing this.  I used to upload products onto the Amazon website so started thinking how would they do this?  Then realised I knew the answer, they have a specific 'search terms' section on their upload forms.  You have to enter all the words / phrases that you want to item to be searchable by.  So I set up a serach terms element for the product type which the umbraco user can then enter any keywords they want to be searchable  I put a regex of lowercase letters and numbers.  I also used a translate() function in my XSLT to force any contents of the text box to lower case then matched the 2 together in my loop.

    I'm sure its not the best way of doing it, but if it's good enough for Amazon should be OK for me.

    If anyone else has any other ideas, I'd love to hear them.

Please Sign in or register to post replies

Write your reply to:

Draft