Search Criterion with date variables

Hi,

I'm using BOS 5.0.9

I'm trying to add a date variable to my search criterion, but can't get the expected results

My code is:

SearchDate start_date = new SearchDate(valueStartDate)
    SearchDate end_date = new SearchDate(valueEndDate)
    query
    .criterion(ProcessInstanceIndex.VARIABLE_NAME).equalsTo(myDate)
    .and(
    .criterion(ProcessInstanceIndex.VARIABLE_VALUE).ranges(start_date.toString(), end_date.toString(), false)

the issue is that this returns the following query:

 AND variable_name:myDate AND variable_value:[20131020230000000 TO 20131121000000000]

this is not what I want, What I need is something that return a query like:

 AND myDate:[20131020230000000 TO 20131121000000000]

not two "ands".

How can I achieve that in my groovy script?

 

Thanks in advance,

 

jCor