Thanks Alex! I was looking at function queries, but somehow missed the ms 
function.

For future reference, this fl parameter did the trick:

fl=*,pastDeadline:if(lt(ms('deadline',NOW),0), true, false)

On a side note though, it would have been nice if the filter query could be 
taken verbatim and inserted into the fl field list. deadline:[* TO NOW] was 
simple enough to convert to function query syntax. But what about something 
more complex? It feels strange to have to convert from one syntax to another. I 
can't be the only one thinking like this, surely? :)

/Jimi

-----Ursprungligt meddelande-----
Från: Alexandre Rafalovitch [mailto:arafa...@gmail.com]
Skickat: den 12 november 2018 15:21
Till: solr-user <solr-user@lucene.apache.org>
Ämne: Re: Include date calculation in field list?

Function query looks like the nearest match to your requirement:
https://lucene.apache.org/solr/guide/7_5/function-queries.html#ms-function

You can use it in the field list too.

Regards,
   Alex.
On Mon, 12 Nov 2018 at 09:12, Hullegård, Jimi 
<jimi.hulleg...@svensktnaringsliv.se> wrote:
>
> Hi,
>
> Maybe I have been working too little with Solr lately, but I'm stuck on a 
> very simple problem (in my mind), and need some help.
>
> How can I include the result of a date calculation in the field list?
>
> For example, let's say that the documents in my index contains the date field 
> 'deadline'. When constructing the query, I can add a filter query like:
>
> deadline:[* TO NOW]
>
> But if I don't want to filter on this, but instead include the "deadline 
> status" (ie past deadline) in the result, how do I achieve that?
>
> I tried:
>
> fl=*,deadline:[* TO NOW]
>
> But then solr complains with the error message "Error parsing fieldname". I 
> then tried to add an alias, as such:
>
> fl=*,pastDeadline:deadline:[* TO NOW]
>
> and that didn't result in an error, but it didn't give me the result I wanted 
> either. This resulted in this field in the result:
>
> <date name="pastDeadline">2007-11-15T11:00:00Z</date>
>
> So the pastDeadline simply contains the date value, when I expected a boolean 
> value "true".
>
> So, how can I achieve this? I would prefer not having to do the date 
> calculation outside of solr.
>
> We use Solr 6.6.4.
>
> Regards
> /Jimi
>
> Svenskt Näringsliv behandlar dina personuppgifter i enlighet med GDPR.
> Här kan du läsa mer om vår behandling och dina rättigheter,
> Integritetspolicy<https://www.svensktnaringsliv.se/dataskydd/integrite
> t-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&ut
> m_medium=email>
Svenskt Näringsliv behandlar dina personuppgifter i enlighet med GDPR. Här kan 
du läsa mer om vår behandling och dina rättigheter, 
Integritetspolicy<https://www.svensktnaringsliv.se/dataskydd/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>

Reply via email to