Copied to clipboard

Flag this post as spam?

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


  • Vishal G.P 62 posts 122 karma points
    Jul 25, 2013 @ 13:58
    Vishal G.P
    0

    XSLT search searching a date field

    Hi all.. still using xstlsearch 2.7 due to old umbraco version..

    Now some pages (doctypes) have a date property field. So the editor chooses a date (eg. 2013-07-25).

    On the frontend of the page this date is formatted to 25 July 2013...

    Now the client want to search for 'july 2013' for example to find items which have this date...

    I added the 'date' field to the 'searchFields' variable in the macro.

    Ofcourse nothing is found, but i'm at a loss of what to change for the proper way to search in a formatted date property of pages... 

    anyone an idea... 

     

    thanks in advance...

     

     

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jul 25, 2013 @ 14:05
    Chriztian Steinmeier
    0

    Hi Vishal,

    Best option would probably be to provide a "Date range" <select> where they could choose a month/year combination - that way you could filter the search results by the dates, instead of having to manually map from "july?" > "07", "dec(ember)?" > "12" etc...

    Neither way is straightforward, I'm afraid...

    /Chriztian

  • Vishal G.P 62 posts 122 karma points
    Jul 25, 2013 @ 14:25
    Vishal G.P
    0

    thanks Chriztian... i will look at both ways you suggested... 

    The thing to do is to filter the matchedNodes further and come up with something smarter.. 

    I think i have enough to check this out further.. 

  • Vishal G.P 62 posts 122 karma points
    Aug 07, 2013 @ 16:00
    Vishal G.P
    0
     <xsl:variable name="evenYetPossibleNodes" select="$yetPossibleNodes[attribute::*[(contains($searchFields,name())
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]
                                              | 
                                              $yetPossibleNodes[*[(contains($searchFields, concat(',',name(.),','))
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]" />
    

    I was playing a bit with this... i was wondering if it isn't possible to filter these more... the only date property there is is called date...

    Isn't is possible to put another or clause to the above filter, where you try to match (contains) the formatted date value to the seachterm..

        <xsl:variable name="evenYetPossibleNodes" select="$yetPossibleNodes[attribute::*[(contains($searchFields,name())
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]
                                              | 
                                              $yetPossibleNodes[*[(contains($searchFields, concat(',',name(.),','))
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]                                               
                                              | 
                                              $yetPossibleNodes[*[(contains(',date', concat(',',name(.),','))
                                              and contains(umbraco.library:FormatDateTime(./date,'dd MMMM yyyy'), $searchTerm)) ]]" />
    

    my xslt is a bit rusty, but i thought the addition would try to convert the ./date field corresponding to the format, and then try to check if the formatted date contains the searchTerm..

    Maybe someone can see why this isn't working well..

  • Vishal G.P 62 posts 122 karma points
    Aug 08, 2013 @ 10:08
    Vishal G.P
    0

    anyone please? The problem with the addition in the query is that i cannot get the value of the ./date property from within the query...

    I see that in the other queries xsltsearch is doing, it gets the complete NODE and strips all HTML and does the search...

    So isnt it possible to do the ./date to get only the date of the node..

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 10:53
    Chriztian Steinmeier
    0

    Hi Vishal,

    It should be possible, though it looks like you've mistyped something - you're testing contains(',date', concat(',', name(), ',')) - which even if the field is called "date" won't work (you'll be checking for ",date," inside the string ",date".

    Try the other way around: contains(concat(',', name(.), ','), ',date')

    And always isolate when testing these things, so you can be sure that any errors are part of the thing you're currently trying to get working, so try just this:

    <xsl:variable name="evenYetPossibleNodes" select="
        $yetPossibleNodes[*[(contains(concat(',', name(), ','), ',date,')
        and contains(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy'), $searchTerm)) ]]" />
    

    ... and test the date stuff before joining with the others.

    /Chriztian

  • Vishal G.P 62 posts 122 karma points
    Aug 08, 2013 @ 11:36
    Vishal G.P
    0

    ahh ok i tried your suggestions...

    But when only isolating the query i get always zero results..

    I then tried the following: query below gives me 488 nodes back (starting point)

    <xsl:value-of select="count($possibleNodes)" />  
    

    the following, just trying to check of the above possibleNodes which one have the date property i get 384 nodes back, which is about right.

    <xsl:variable name="evenYetPossibleNodes" select="$yetPossibleNodes[*[(contains(concat(',', name(), ','), ',date,')]]" />
    

    But when i now try to go and match the (formatted) date to the searchTerm (uppercased) i get zero results

    <xsl:variable name="evenYetPossibleNodes" select="
    $yetPossibleNodes[*[(contains(concat(',', name(), ','), ',date,')
    and contains(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy'), $searchTerm)) ]]" />
    

    i even tried uppercasing the formatedDate, because the $searchTerm is uppercased, with no better results (0 results).

     <xsl:variable name="evenYetPossibleNodes" select="$yetPossibleNodes[*[(contains(concat(',', name(), ','), ',date,')
                                              and contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), $searchTerm)) ]]" />
    

    My searchterm is just 'may 2010', i have nodes (news items) which have a publication date in may 2010... Even 'may' or '2010' doesnt return anything.

    So i guess in the second part of the query where the matching takes place it doesnt really matches...

  • Vishal G.P 62 posts 122 karma points
    Aug 08, 2013 @ 16:14
    Vishal G.P
    0

    couple of hours passed and i tried couple of things, but now i might think that maybe we are not in the correct context in the second part of the query, but i'm not sure... sigh.. i'm a bit frustrated and the client is breathing down my neck :-)

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 16:28
    Chriztian Steinmeier
    0

    OK, so maybe try this very hardcoded stuff to see where things go wrong:

    <xsl:variable name="nodesWithDate" select="$yetPossibleNodes[date]" />
    
    <xsl:variable name="lookForMAY" select="
        $nodesWithDate[contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), 'MAY')]" />
    
    <xsl:variable name="lookForMAY2010" select="
        $nodesWithDate[contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), 'MAY 2010')]" />
    
    <p>With date: <xsl:value-of select="count($nodesWithDate)" /></p>
    <p>MAY: <xsl:value-of select="count($lookForMAY)" /></p>
    <p>MAY2010: <xsl:value-of select="$lookForMAY2010" /></p>
    

    /Chriztian

  • Vishal G.P 62 posts 122 karma points
    Aug 08, 2013 @ 16:48
    Vishal G.P
    0

    Hi Chriztian:

    EDIT: sorry.... I did something wrong previously:

    this works

    <p>
        With date: 384</p><p>
        MAY: 41</p><p>
        MAY 2010: 2</p>
    

    Which is correct...

    We query directly on the set now.. in the previous example we query on a filter of a filter (??) because i see two '[' brackets...

    My xslt is a bit rusty...

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 16:55
    Chriztian Steinmeier
    100

    Ok - next step (I see I forgot a count() in the last one - but it would be zero too, I'm sure)

    <xsl:variable name="nodesWithDate" select="$yetPossibleNodes[date]" />
    
    <xsl:variable name="lookForMAY" select="
        $nodesWithDate[contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), 'MAY')]" />
    
    <xsl:variable name="lookForMAY2010" select="
        $nodesWithDate[contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), 'MAY 2010')]" />
    
    <p>With date: <xsl:value-of select="count($nodesWithDate)" /></p>
    <p>MAY: <xsl:value-of select="count($lookForMAY)" /></p>
    <p>MAY2010: <xsl:value-of select="count($lookForMAY2010)" /></p>
    
    <xsl:for-each select="$nodesWithDate">
        <xsl:variable name="formattedDate" select="umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')" />
        <p>
            <xsl:value-of select="@nodeName" />,
            <xsl:value-of select="date" />,
            <xsl:value-of select="$formattedDate" />,
            <xsl:value-of select="ps:uppercase($formattedDate)" />
        </p>
        <hr/>
    </xsl:for-each>
    

    As you can see we now need to see what the actual Formatted Dates resolve to - my guess is that you're getting localized monthnames...

    /Chriztian

  • Vishal G.P 62 posts 122 karma points
    Aug 08, 2013 @ 21:32
    Vishal G.P
    0

    Thanks alot for your help and insight Chriztian!!... i now managed to change the filtering to match the correct dates...

    the final code is now this(which seen now was very simple)... i dont know why i was caught in the code used already to filter by xsltsearch code...

    <xsl:variable name="evenYetPossibleNodes" select="$yetPossibleNodes[attribute::*[(contains($searchFields,name())
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]
                                              | 
                                              $yetPossibleNodes[*[(contains($searchFields, concat(',',name(.),','))
                                              and contains(ps:uppercase(umbraco.library:StripHtml(string(.))), $searchTerm)) ]]
                                              |
                                              $yetPossibleNodes[date and contains(ps:uppercase(umbraco.library:FormatDateTime(date, 'dd MMMM yyyy')), $searchTerm)] "/>
    
Please Sign in or register to post replies

Write your reply to:

Draft