cancel
Showing results for 
Search instead for 
Did you mean: 

Lucene query for a Date range

abirb
Champ in-the-making
Champ in-the-making
I need to incorporate a lucene Serach for docs in a specified location on a particular date range. I have used the following lucene query , but it throws up an error in the response file

500 Description: An error inside the HTTP server which prevented it from fulfilling the request.

Message: Error during processing of the template 'Expression resultset is undefined on line 7, column 8 in SearchDate.post.html.ftl.'. Please contact your system administrator.

the controller file (lucene search)
var nodes = search.luceneSearch("date:\" [2008\-10\-30T00:00:00 TO 2008\-10\-30T00:00:00]);
model.resultset=nodes;

I guess my query string format is not correct …

<html>
  <body>
    <img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" />
    Date Searched for : PUT THE DATES HERE
    <br>
    <table>
<#list resultset as node>
     <tr>
       <td><img src="${url.context}${node.icon16}"/>
       <td><a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}">${node.name}</a>
     </tr>
</#list>
    </table>
  </body>
</html>

Thanks in Advance
4 REPLIES 4

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

Try the below code as an example.

var nodes = search.luceneSearch("@cm\\:modified:[2005\-10\-30T00:00:00 TO 2008\-10\-30T00:00:00]");
model.resultset = nodes;


Date is not one of the fields that can be searched like PATH,TEXT,ID etc.

The example used in SEARCH API wiki page is (http://wiki.alfresco.com/wiki/Search#The_Search_API)

@test\:date:[2003\-12\-16T00:00:00 TO 2003\-12\-17T00:00:00]

@test is the  prefix for your model and date is the property.

You could search on any property this way ( created,expiryDate etc.)

Best Regards,
Shagul

sbuckle
Champ in-the-making
Champ in-the-making
I think your query is formatted incorrectly and you might also want to try specifying an end date that is greater than the start date - currently both the start and end dates are the same!

Try this:


var nodes = search.luceneSearch("date:[2008-10-30T00:00:00 TO 2008-10-30T00:00:00]");
model.resultset=nodes;

abirb
Champ in-the-making
Champ in-the-making
Thanks all , for the guidance

Now I have been able to modify the query hopefully got it right ..

fdate="2008\-10\-28T00:00:00";
        tdate="2008\-10\-29T00:00:00";
       spath="'+PATH:\"/app:company_home//*\" + ";
       scontent="@\\{http\\://www.alfresco.org/model/content/1.0\\}content.mimetype:text/plain + ";
       qdate="@cm\\:created:[" + fdate + " TO " + tdate +"]'";
       strq=spath+scontent+qdate;
      // logger.Log(">>>> Fdate " +fdate + ">>>>>TDate " + tdate);
        //document.writeln("Test");
        // perform the search
         var nodes=search.luceneSearch(strq);
         model.resultset=nodes;


The above works fine !!!

Thanks again

ppurcellrr
Champ in-the-making
Champ in-the-making
Just so someone else can have an easier time than I  did.

var searchResults = null;
var queryStr = ' PATH:"/app:company_home/st:sites/cm:'+siteStr+'/cm:documentLibrary//*" AND TYPE:"cm:content" AND +@customModelName\\:contractDate:[NOW TO "2014-07-09"]';

I had the  above query in a javascript file .

Getting the PATH and  TYPE subsections working was straight forward however the date range was tricky



I found the problem lay in the  back slashes after the custom model name

I had

+@customModelName\:contractDate:[NOW TO "2014-07-09"];

Which according  to  most of the post I have read should work however  it did not. That date range did work in the Search query field

Once I changed \ to \\ (+@customModelName\\:contractDate:[NOW TO "2014-07-09"]Smiley Wink the query worked.

so the form I had success with is +@customModelName\\:customPropertyName:date range.

Make sure you watch escaping of characters.

I also recommend the Alfresco Javascript console https://code.google.com/p/share-extras/wiki/JavascriptConsole
It really sped the process up.