Include date calculation in field list?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Include date calculation in field list?

Hullegård, Jimi
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/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>
Reply | Threaded
Open this post in threaded view
|

Re: Include date calculation in field list?

Alexandre Rafalovitch
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
<[hidden email]> 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/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>
Reply | Threaded
Open this post in threaded view
|

SV: Include date calculation in field list?

Hullegård, Jimi
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:[hidden email]]
Skickat: den 12 november 2018 15:21
Till: solr-user <[hidden email]>
Ä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 <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: Include date calculation in field list?

Alexandre Rafalovitch
Actually,

It is not just two syntax versions. The query parser is an interface
and there are many variations in parsing, depending on the parser
chosen. See for example the long list at:
https://lucene.apache.org/solr/guide/7_5/other-parsers.html

Of course, one of those many parsers allows you to use Function Query
definition, so maybe that's a way to unify things:
https://lucene.apache.org/solr/guide/7_5/other-parsers.html#function-query-parser

Regards,
   Alex.
On Tue, 13 Nov 2018 at 04:28, Hullegård, Jimi
<[hidden email]> wrote:

>
> 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:[hidden email]]
> Skickat: den 12 november 2018 15:21
> Till: solr-user <[hidden email]>
> Ä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 <[hidden email]> 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>