Gravatar for

Question by krislutz, Feb 5, 2015 6:29 PM

javascript query expression using a date

I have a query expression where I am trying to change the relevance of a document based on the year. I am sure there is a better way to write this but I don't know why what I have is not changing the ranking at all, here is the qre for a sample year which has no affect (Date is a datetime field)

        args.queryBuilder.advancedExpression.add("$qre(expression:'@(Model.ToCoveoFieldName("Date")) *= \"2014*\" AND @(Model.ToCoveoFieldName("templatename")) == \"Press-Release\"', modifier:'99')");
Gravatar for

Comment by Luc Bergeron, Feb 6, 2015 8:17 AM

Is your search interface sorting by "Relevance"? Sorting on a field will override query ranking expressions (QRE).

Gravatar for

Comment by krislutz, Feb 6, 2015 12:04 PM

I actually got it working by changed the query slightly. Coveo wouldn't let me run a like comparison on the a date field in the admin so that was likely the issue. This works instead.. args.queryBuilder.advancedExpression.add("$qre(expression:'@(Model.ToCoveoFieldName("Date")) = 2010/01/01..2010/12/31 AND @(Model.ToCoveoFieldName("templatename")) == \"Press-Release\"', modifier:'-10')");

2 Replies
Gravatar for

Answer by Vincent Séguin, Feb 5, 2015 6:41 PM


First thing i would do is to actually validate if the resulting query (what is written in the expression part) returns results in the Index Browser (in the CES Admin Tool). I suspect your query doesn't return any results.

Gravatar for

Answer by Daniel Lavoie, Feb 6, 2015 3:58 PM

There is a field inside coveo named sysyear, so all you need to do is query for sysyear:2014. Using an advanced expression like a range scan or a wildcard pattern will be orders of magnitude slower, which won't necessarily be problematic on a small index but will start having an impact on a larger one.

Gravatar for

Comment by krislutz, Feb 6, 2015 5:56 PM

thanks for the info. Our date field is custom so the year wouldn't actually match sysyear, however I imagine I could achieve the same results creating a computed field that only holds our custom year so might give that a shot.

Ask a question