How to create a field that is searchable by giving a range

cancel
Showing results for 
Search instead for 
Did you mean: 
hiten_rastogi1
Established Member

How to create a field that is searchable by giving a range

Hi,

I have three fields that contains values for the tenure of a contract, e.g. custom:tenureYear=5, custom:tenureMonth=11 and custom:tenureDays=3, these fields are simple text, non editable and are calculated through a behavior.

I want that in the adv. search form I can have three other fields in which I can input a range for custom:tenureYear, custom:tenureMonth and custom:tenureDays and display the result, e.g. showing in the search results the contracts that have tenure years of 4 and 5 I can input a to and from field with value 4 and 5 and it fetches the results by checking the custom:tenureYear for every contract and values that lies in between the to and from values are displayed as a result.

Thanks

Hiten Rastogi

4 Replies
afaust
Master

Re: How to create a field that is searchable by giving a range

Configure the search form to use the numberrange.ftl form control template for the fields you need. I would also adivse you to change the data model to use d:int instead of d:text for these properties, otherwise the sorting of the field values may not be correct and you might end with incorrect results of range queries too.

hiten_rastogi1
Established Member

Re: How to create a field that is searchable by giving a range

Thanks Axel,

I will give this a try.

andy1
Senior Member

Re: How to create a field that is searchable by giving a range

Hi

It is easy to fall into the trap of describing why your solution does not work and skip the problem ....

Is the route cause that we do not index duration very well? I assume that the start and end dates for the contract are not enough and you want something that also includes the contract length. One way to do duration is simply with numeric fields for days etc described. You can probably abuse date relative to some fixed point in the past and then use SOLR date math in your queries for duration - with easy rounding and date math. You would have to do some query building.

Andy 

hiten_rastogi1
Established Member

Re: How to create a field that is searchable by giving a range

Thanks Andy for you input. I was able to overcome the challenge by using number range ftl as described by Axel above.