Select Page

By default, collation for datetime fields in Alfresco does not include time.  The reason for this is that the Lucene “analyzer” (component responsible for writing values to the index and searching them) used for datetime attributes only deals with the date portion. If you need to search or sort by date + time, you’ll need to configure Lucene to use a different analyzer for datetime attributes.

Analyzers are defined in a file named dataTypeAnalyzers.properties, which defines analyzers for all types.  You can override the analyzer for a single data type (datetime in this case) by introducing a custom properties file with a definition for just that type.

In the following example, I am working in a project that defines a custom content model.  Using the spring context that loads the custom model, I also load a custom dataTypeAnalyzers.properties file to override the default indexing behavior for the datetime type.  Note that I am using Alfresco 3.4.

First, I create the custom dataTypeAnalyzers.properties, which I chose to place in the same directory with my custom content model definition.  The file has just one line, which sets the analyzer for datetime to DateTimeAnalyser rather than DateAnalyser:

d_dictionary.datatype.d_datetime.analyzer=org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser

Then, we need to refer to that properties file from a spring context.  I have followed the way Alfresco has done it for the OOTB model by referring to it from my custom model context.





  
  
    
      
        alfresco/extension/model/sample-model.xml
      
    
    
      
        alfresco/extension/model/dataTypeAnalyzers
        alfresco/extension/model/sample
      
    
  


After deploying this change, it’s necessary to rebuild the Lucene index. Consult Alfresco’s documentation for information on rebuilding the index.

Pin It on Pinterest

Sharing is caring

Share this post with your friends!