cancel
Showing results for 
Search instead for 
Did you mean: 

Sort query by DateTime

lpgc
Champ in-the-making
Champ in-the-making
Hi,

Ive defined a custom datetime field (@intra:bookdate) and i perform a simple query that should sort by it:

var nodes = search.luceneSearch(query,"@intra:bookdate","false",10);

The query gives the correct results, but doesnt sort correctly.

Any help ??

***********************
** Some info follows **
***********************

==> Alfresco Community v4.2.0 (4576) schema 6.022

==> model

<property name="intra:bookdate">
<title>Booking Date</title>
<type>d:datetime</type>
</property>
7 REPLIES 7

abarisone
Star Contributor
Star Contributor

lpgc
Champ in-the-making
Champ in-the-making
Thanks for the info 🙂

Ill try this way of defining a query. Hopefully it will work!

lpgc
Champ in-the-making
Champ in-the-making
Hi,

i tried the new code and atleast two results arent ordered correctly (even though the date, with time, is correct)

Any new idea of why could this be happening?

Thanks in advance 🙂

** CODE:

var sort = {
     column: '@intra:bookdate',
     ascending: false  
};

var paging = {
     maxItems: 10,
     skipCount: 0  
};  

var def = {
     query: '@intra\\:active:true',
     language: 'fts-alfresco',
     sort: [sort],
     page: paging  
};  

var results = search.query(def)

model.nodes = results;

abarisone
Star Contributor
Star Contributor
Hi,
take a look here for an issue about date sorting http://forums.alfresco.com/forum/developer-discussions/repository-services/alfresco-lucene-search-so...
Maybe you can get some hints about this strange behaviour.

Regards,
Andrea

lpgc
Champ in-the-making
Champ in-the-making
Hi again,

I read that post before and checked all the steps needed. My file has the correct entry:

* dataTypeAnalyzers.properties:
d_dictionary.datatype.d_datetime.analyzer=org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser

The query responds with a correct DateTime format (dd/mm/aaaa HH:MM)

Im sure im missing something really lame or im doing something really wrong!

Hope that with some help the issue can be fixed 🙂

PS-the line was already included in Alfresco 4 (no real need to add it)

andy
Champ on-the-rise
Champ on-the-rise
Hi

Can you please add you property definition.
Are you using the lucene or SOLR search sub-systems?

The property definition should be like that for created:

    <property name="mySmiley Tongueroperty">
        <title>My property</title>
        <type>d:datetime</type>
        <index enabled="true">
       <atomic>true</atomic>
            <stored>false</stored>
            <tokenised>both</tokenised>
        </index>
    </property>


Dates and strings etc need to be tokenised "both" to support ordering and query.

Andy

lpgc
Champ in-the-making
Champ in-the-making
Hi,

Thanks for trying to help. This is the info you requested:

* property

<property name="intra:bookdate">
<title>Booking Date</title>
<type>d:datetime</type>
</property>

* my Alfresco v4.2.0 (4576) schema 6.022 install uses a out of the box solr.

To start with i defined "intra:bookdate" as "d:date" but decided to add time to have better control over the results. After i did a re-index as seen on a forum post (basically i stop Alfesco, deleted some files from "alf_data" and started Alfresco again); ordering still didnt work though.

Im not sure how to tokenise the date because i just set the ordening parameter to "intra:bookdate".

As i hint and maybe to help others in my same situation (im not sure if its a real issue or me not having the correct knowledge) i can add that sorting by two parameters WORKS. In my case i order by "intra:bookdate" and  "cm:modified" (both are datetime).

Thanks for any help 🙂