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...
<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..
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:
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 :-)
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...
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
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..
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..
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..
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..
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:
... and test the date stuff before joining with the others.
/Chriztian
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)
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.
But when i now try to go and match the (formatted) date to the searchTerm (uppercased) i get zero results
i even tried uppercasing the formatedDate, because the $searchTerm is uppercased, with no better results (0 results).
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...
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 :-)
OK, so maybe try this very hardcoded stuff to see where things go wrong:
/Chriztian
Hi Chriztian:
EDIT: sorry.... I did something wrong previously:
this works
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...
Ok - next step (I see I forgot a count() in the last one - but it would be zero too, I'm sure)
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
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...
is working on a reply...