Copied to clipboard

Flag this post as spam?

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


  • Jake 23 posts 53 karma points
    Feb 19, 2010 @ 12:36
    Jake
    0

    Umbraco Search

    Can anyone tell me how I can search a field with a term eg:

    Search Number of bedrooms with a value from a dropdown such as 2 and also search a price range such as 100000-200000 and show any nodes with price values in that range?

     

    Thaks in advance

  • Seth Niemuth 275 posts 397 karma points
    Feb 19, 2010 @ 15:44
    Seth Niemuth
    0

    You can use XSLT search as a base: http://www.percipientstudios.com/xsltsearch/overview.aspx. You can use it to search specific document type properties. You will probably have to extend it to make a customized search with dropdowns like you want but this will have done a lot of the work for you.

  • Jake 23 posts 53 karma points
    Feb 19, 2010 @ 16:00
    Jake
    0

    Thaks, I have started with this. I am having a problem searching a range like 100000-200000

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 20, 2010 @ 09:56
    Douglas Robar
    0

    This would require a modification to XSLTsearch.

    The easy way to do it would be to have two field or drop-down lists for the start and end range values on your form. Then, add that to your criteria in XSLTsearch. This blog post will explain the XSLTsearch modification, which is very simple. http://blog.percipientstudios.com/2009/4/7/customizing-xsltsearch.aspx

    The more difficult way would be to parse the search field and look for a dash (-) to split() out the two terms. But I don't think that's as helpful for users as then they'd never be able to search for a dash character.

    cheers,
    doug.

     

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 12:30
    Jake
    0

    Thanks for this. I can get xslt to search a type of node but how do I limit it to search just 2 fields, price and bedrooms?

     

    thanks

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 13:46
    Jake
    0

    Basically what I want to do is something like on this page http://www.haddenrankin.com/sell-with-us.aspx without the area field. Can you point me in the right direction please?

  • Bogdan 250 posts 427 karma points
    Feb 22, 2010 @ 14:53
    Bogdan
    0

    Hi Jake,

    a filter like that is pretty easy to do in a user control, with the help of http://our.umbraco.org/wiki/how-tos/useful-helper-extension-methods-%28linq--null-safe-access%29. Lets say you have a node with all the properies for sale, each of them having a number of bedrooms and a price. In your user control you can do something like

    Node properties = new Node(nodeId);
    IEnumerable<Node> selection = properties.AllChildren().Where(p => p.GetPropertyAsInt("bedrooms") > someValueBedrooms).Where(p => p.GetPropertyAsInt("price") < someValuePrice);
  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 15:08
    dandrayne
    0

    Hi Jake

    If you have a look at http://our.umbraco.org/forum/developers/xslt/6751-Search-based-on-dropdowns-using-XSLT?p=0 you'll see how I did the dropdown search on haddenrankin, or at least a small part of it.  What in particular are you having trouble with?

    Dan

     

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 15:14
    Jake
    0

    What I want to do is pass the values to the serch macro via a user control. So I need to split the values out and then feed them into the xslt. I think I will need to first select all the nodes of type - propertyDetails and then compare this result with the search query string. noBedrooms = search string. I'm just more used to SQL than xslt so I keep banging my head against a brick wall!!

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 15:33
    Jake
    0

    Hi dandrayne, I have had a look through this and I think where I am hitting a problem is that I want to be able to compare the sub nodes of propertylist to match the search critera for Number of bedrooms and minimum Price. This example compare the sub nodes of a categroy. Am I correct?

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 15:51
    dandrayne
    0

    Hi Jake

    I'd need to see the xml/node structure that you're searching and the xslt you have so far, as I'm not sure of the distinction between a property list and a category subnode

    Dan

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 15:57
    Jake
    0

    I have a node of propertyList with subnodes that are propertyDetails so "proertList/propertyDetails". On the propertydetails node I have data [@alias = 'noBedroomsDetails'] and data [@alias = 'propertyPrice'].

    I have tried many different versions of xsly so far and came across your one. I think this will work

    <xsl:variable name="minrooms">
    <xsl:choose>
           
    <xsl:when test="umbraco.library:Request('minrooms') &lt;= 0 or string(umbraco.library:Request('minrooms')) = '' or string(umbraco.library:Request('minrooms')) = 'NaN'">0</xsl:when>
           
    <xsl:otherwise>
                   
    <xsl:value-of select="umbraco.library:Request('minrooms')"/>
           
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 16:16
    dandrayne
    0

    Yes the code above will grab the querystring value for "minrooms" without problem.  In the code listed at http://our.umbraco.org/forum/developers/xslt/6751-Search-based-on-dropdowns-using-XSLT?p=0 I'm also checking for subnodes that contain the values.

    Can you post a sample of the xml you are searching?  Or are your properties stored in umbraco?

    Dan

     

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 16:24
    Jake
    0

    All stored in Umbraco, my approach now is to fist find all matching sub nodes of property list and then filter them by Number of bedrooms and by price. Just working out how to do that! So far what I have is basic.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:ps="urn:percipientstudios-com:xslt"
        exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>




      <xsl:template match="/">


        <!-- GET CATEGORY QUERY STRING -->
        <xsl:variable name="noBedroomsDetailsquery">
          <xsl:value-of select="umbraco.library:RequestQueryString('search')" />
        </xsl:variable>

     


        <!-- GET noBedroomsDetails QUERY STRING -->
        <xsl:variable name="propertyPricequery">
          <xsl:value-of select="umbraco.library:RequestQueryString('search')" />
        </xsl:variable>


    <xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeName ='Property List']/node">
        <xsl:call-template name="displayResults" />
        </xsl:for-each>





      </xsl:template>

    <xsl:template name="displayResults">
      <div id="resultsDetails">
        <table id="reultsDetailstbl" cellspacing="0">
          <tr>
            <td rowspan="3" class="imageCol">
              <a href="{umbraco.library:NiceUrl(@id)}" class="">

                <img src="{data [@alias ='propertyThumbnail']}" class="propertyThumbnail" alt="{@nodeName}"/>

              </a>
            </td>
            <td class="titleList" colspan="2">
              <h2>
                <xsl:value-of select="data [@alias = 'propertyTypeTitle']"/>
              </h2>
            </td>
          </tr>
          <tr>
            <td class="detailsList">
              <ul id="resultsList" style="margin-left: 0; padding-left: 5px;">

                <li>
                  from <xsl:value-of select="format-number(data[@alias = 'propertyPrice'],'£###,###')"/>
                </li>
                <li>
                  <xsl:value-of select="data [@alias = 'noBedroomsDetails']"/>  Bedrooms
                </li>
              </ul>
            </td>
            <td class="detailsList">
              <a href="{umbraco.library:NiceUrl(@id)}" class="">

                <img src="/img/detailsBtn.gif" class="detailsBtn" alt="{@nodeName}"/>

              </a>
            </td>
          </tr>
          <tr>
            <td class="shortDetails" colspan="2">
              <xsl:value-of select="data [@alias = 'propertyDescShort']"/>
            </td>
          </tr>
        </table>

        <hr style="color: #f3f1ed; background-color:#f3f1ed; border:0px; height:2px; text-align: 'left'; width: '100%'"/>
      </div>


    </xsl:template>


    </xsl:stylesheet>



     

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 16:34
    dandrayne
    100


    ok so here's what we know:

    * You have a node of type "Property List"
    * Under this you have nodes of type "Property Details"
    * Under these you have properties e.g. no of bedrooms ("noBedroomsDetails")

    So to do a search based on the value from a querystring (which I'm pretending is in a xsl:variable called "minrooms")

    <xsl:variable name="minrooms">
    <xsl:choose>
    <xsl:when test="umbraco.library:Request('minrooms') &lt;= 0 or string(umbraco.library:Request('minrooms')) = '' or string(umbraco.library:Request('minrooms')) = 'NaN'">0</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:Request('minrooms')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>



    <xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]//node[@nodeTypeAlias='Property List']/node[@nodeTypeAlias='Property Details' and string(./data[@alias='noBedroomsDetails']) = $minrooms]">
    <p>
    <xsl:value-of select="current()/@nodeName" />
    </p>
    </xsl:for-each>

    This is untested, but it looks about right. Although the above is a little long, it's because I don't know where the search is taking place, so I go right back up to the homepage, then I find a node of type "Property List", then iterate through the child nodes testing the properties as I go.

    Dan

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 16:35
    dandrayne
    0

    Oops, "min rooms", not = rooms

    <xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]//node[@nodeTypeAlias='Property List']/node[@nodeTypeAlias='Property Details' and string(./data[@alias='noBedroomsDetails']) &gt;= $minrooms]">
    <p>
    <xsl:value-of select="current()/@nodeName" />
    </p>
    </xsl:for-each>

     

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 17:06
    Jake
    0

    Thanks for this, getting somewhere now. How can I set a variable value in xslt for testing, ie hard code the value so that I can build the results without the query string for now?

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 17:09
    dandrayne
    0

    Instead of

    <xsl:variable name="minrooms">
    <xsl:choose>
           
    <xsl:when test="umbraco.library:Request('minrooms') &lt;= 0 or string(umbraco.library:Request('minrooms')) = '' or string(umbraco.library:Request('minrooms')) = 'NaN'">0</xsl:when>
           
    <xsl:otherwise>
                   
    <xsl:value-of select="umbraco.library:Request('minrooms')"/>
           
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    Just do something like

    <xsl:variable name="minrooms">2</xsl:variable>

    But you can also just manually add the querystring to your page  e.g.  mypage.aspx?minrooms=2

    Dan

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 17:17
    Jake
    0

    Thanks, am now getting along well. I will post my final code for you to have a giggle at!

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 17:42
    Jake
    0

    One more thing, what is the best way of sorting my query string of http://localhost:5001/results.aspx?search=0,2000000 into two variables? Can this be done in xslt?

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 18:04
    dandrayne
    0

    You can use umbraco.library:Split to split the value at the comma, but why not make life easier for yourself and send two paramaters (maxprice and minprice)?

    Dan

  • Jake 23 posts 53 karma points
    Feb 22, 2010 @ 18:10
    Jake
    0

    Hi, Thanks, ignore me I had brain fade. Thanks for all your help, I have voted you MVP

    Here is the final code for a search string

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:ps="urn:percipientstudios-com:xslt"
        exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>




      <xsl:template match="/">


        <!-- GET CATEGORY QUERY STRING -->
        <xsl:variable name="noBedroomsDetailsquery">
          <xsl:value-of select="umbraco.library:RequestQueryString('search')" />
        </xsl:variable>

     


        <!-- GET noBedroomsDetails QUERY STRING -->
        <xsl:variable name="propertyPricequery">
          <xsl:value-of select="umbraco.library:RequestQueryString('price')" />
        </xsl:variable>






        <xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeName ='Property List']/node[@nodeTypeAlias='PropertyDetails' and string(./data[@alias='noBedroomsDetails']) >= $noBedroomsDetailsquery and string(./data[@alias='propertyPrice']) &lt;= $propertyPricequery]">
          <p><xsl:value-of select="$noBedroomsDetailsquery" /><xsl:value-of select="data [@alias = 'noBedroomsDetails']"/></p>
        <xsl:call-template name="displayResults">
              </xsl:call-template>

        </xsl:for-each>









      </xsl:template>

    <xsl:template name="displayResults">
      <div id="resultsDetails">
        <table id="reultsDetailstbl" cellspacing="0">
          <tr>
            <td rowspan="3" class="imageCol">
              <a href="{umbraco.library:NiceUrl(@id)}" class="">

                <img src="{data [@alias ='propertyThumbnail']}" class="propertyThumbnail" alt="{@nodeName}"/>

              </a>
            </td>
            <td class="titleList" colspan="2">
              <h2>
                <xsl:value-of select="data [@alias = 'propertyTypeTitle']"/>
              </h2>
            </td>
          </tr>
          <tr>
            <td class="detailsList">
              <ul id="resultsList" style="margin-left: 0; padding-left: 5px;">

                <li>
                  from <xsl:value-of select="format-number(data[@alias = 'propertyPrice'],'£###,###')"/>
                </li>
                <li>
                  <xsl:value-of select="data [@alias = 'noBedroomsDetails']"/>  Bedrooms
                </li>
              </ul>
            </td>
            <td class="detailsList">
              <a href="{umbraco.library:NiceUrl(@id)}" class="">

                <img src="/img/detailsBtn.gif" class="detailsBtn" alt="{@nodeName}"/>

              </a>
            </td>
          </tr>
          <tr>
            <td class="shortDetails" colspan="2">
              <xsl:value-of select="data [@alias = 'propertyDescShort']"/>
            </td>
          </tr>
        </table>

        <hr style="color: #f3f1ed; background-color:#f3f1ed; border:0px; height:2px; text-align: 'left'; width: '100%'"/>
      </div>


    </xsl:template>


    </xsl:stylesheet>



     

  • dandrayne 1138 posts 2262 karma points
    Feb 22, 2010 @ 18:18
    dandrayne
    0

    Heh, cheers ^^

    good luck!

Please Sign in or register to post replies

Write your reply to:

Draft