cancel
Showing results for 
Search instead for 
Did you mean: 

Query Search with space and range date parameter

ant_batt
Champ in-the-making
Champ in-the-making
Hi to all,

I have a problem. I want to search, with Web Service, a content that have a date range (that user insert in input) and are present in a specific space.
I have try with this code, but the result is a ResultsSet of content that are present in a space that I don't want



SimpleDateFormat df = CachingDateFormat.getDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", true);
Calendar cal = Calendar.getInstance();
String dateF = df.format(cal.getTime());
cal.add(Calendar.MONTH, -1);
String dateI = df.format(cal.getTime());
String path="'+PATH:\"/app:company_home/cm:portale/cm:Istruzione/cm:Contenuti/cm:Home/cm:normativa/*\" + ";
String range="@cm\\:created:[" + dateI + " TO " + dateF +"]'";
String str=path+range;
Query query = new Query(Constants.QUERY_LANG_LUCENE, str);
QueryResult queryResult = repositoryService.query(STORE, query, false);

Thanks
3 REPLIES 3

chooli
Champ in-the-making
Champ in-the-making
Try the following codes, I had the same case like yours in my project


GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.MONTH,-1);
String monthAgo = new SimpleDateFormat("yyyy-MM-dd").format(gc.getTime());

String path="+PATH:\"/app:company_home/cm:portale/cm:Istruzione/cm:Contenuti/cm:Home/cm:normativa/*\"";
String range=" +@cm\\:created:[" + monthAgo + "T00:00:00 TO NOW]";
String str=path+range;
Query query = new Query(Constants.QUERY_LANG_LUCENE, str);
QueryResult queryResult = repositoryService.query(STORE, query, false);

I didn't test these codes, but it should work

ant_batt
Champ in-the-making
Champ in-the-making
Thaks chooli,
works fine but I didn't understand what's wrong in my code.

rscottm
Champ in-the-making
Champ in-the-making
Your problem might have been this line

String range="@cm\\:created:[" + dateI + " TO " + dateF +"]'";

needing to read like this

String range=" +@cm\\:created:[" + dateI + " TO " + dateF +"]'";

?  Not sure if it caused the entire problem, but I think the leading space and + are required.

Hope it helps,
scott