Gravatar for d.kumar.chittimilla@accenture.com

Question by dkchittimilla, Apr 17, 2017 5:49 PM

Querying against a computed date field

Hi All,

In our application we have a requirement to filter the records against date field. For this, we wrote a computed field which returns date in below format

Ex: 2015/08/27@04:00:00Z

We added a field expression like below to filter the records which were created after 2016/01/01

queryBuilder.advancedExpression.addFieldExpression('@modifieddate', '>', ['2016/01/01']);

But when we run the code, it is giving results which are even less than mentioned date which implies not giving correct results. Could you please suggest me if I miss anything.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Apr 17, 2017 6:16 PM

Which product are you using? Coveo for Salesforce? Coveo for Sitecore? Which version?

Could you check in the network tab what is the whole advanced query? Something might be overriding this date filter.

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Apr 18, 2017 12:04 PM

Coveo for Sitecore fields needs to be translated to work properly, did you translate it? You should end up with a field like this: `@fmodifieddate12345`

You should check Coveo Fields Resources Component, it contains methods to translate fields according to your configuration.

Also:

You should check the Working with Fields topic for more information.

Gravatar for d.kumar.chittimilla@accenture.com

Comment by dkchittimilla, Apr 18, 2017 12:29 PM

Hi,

Yes. We added in the same way.

Under <fieldNames hint="raw:AddFieldByFieldName"> we added

<fieldType fieldName="customdate"  sortable="true" isFacet="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" type="System.DateTime" returnType="System.DateTime" />

and under <fields hint="raw:AddComputedIndexField"> we added

<field fieldName="customdate">MyProject.Search.Computed.CustomDateComputedField,MyProject.Search</field> 

and we are getting field @fcustomdate12345 added to each document. We are getting the value for field in below format

Ex: 2015/08/27@04:00:00Z

Above I mentioned @modifieddate in query just as an example.

Ask a question