Computed fields - can I put a function in fl?

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

Computed fields - can I put a function in fl?

maurizio1976
Hi,
I have 2 fields, one containing a string (product) and another containing a boolean (show_product).

Is there a way of returning the product field with a value of null when the show_product field is false?

I can make another field (product_computed) and index that with null where I need but I would like to understand if there is a better approach like putting a function query in the fl and make a computed field.

something like:
q=*:*&fq=&start=0&rows=10&fl=&qt=&wt=&explainOther=&hl.fl=product:(if(show_product:true, product, "")

that obviously doesn't work.

thanks for any help

Maurizio
Reply | Threaded
Open this post in threaded view
|

Re: Computed fields - can I put a function in fl?

Erick Erickson
I think in 4.0 you can, but not 3.x as I remember. Your example has
the fl as part
of the highlight though, is that a typo?

Best
Erick

On Fri, Jul 13, 2012 at 5:21 AM, maurizio1976
<[hidden email]> wrote:

> Hi,
> I have 2 fields, one containing a string (product) and another containing a
> boolean (show_product).
>
> Is there a way of returning the product field with a value of null when the
> show_product field is false?
>
> I can make another field (product_computed) and index that with null where I
> need but I would like to understand if there is a better approach like
> putting a function query in the fl and make a computed field.
>
> something like:
> q=*:*&fq=&start=0&rows=10&fl=&qt=&wt=&explainOther=&hl.fl=/*product:(if(show_product:true,
> product, "")*/
>
> that obviously doesn't work.
>
> thanks for any help
>
> Maurizio
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Computed-fields-can-I-put-a-function-in-fl-tp3994799.html
> Sent from the Solr - User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Computed fields - can I put a function in fl?

maurizio1976
Yes,
sorry Just a typo.
I meant  q=*:*&fq=&start=0&rows=10&qt=&wt=&explainOther=&fl=product:(if(show_product:true,
product, "")
thanks


On Sat, Jul 14, 2012 at 11:27 PM, Erick Erickson [via Lucene]
<[hidden email]> wrote:

> I think in 4.0 you can, but not 3.x as I remember. Your example has
> the fl as part
> of the highlight though, is that a typo?
>
> Best
> Erick
>
> On Fri, Jul 13, 2012 at 5:21 AM, maurizio1976
> <[hidden email]> wrote:
>
>> Hi,
>> I have 2 fields, one containing a string (product) and another containing
>> a
>> boolean (show_product).
>>
>> Is there a way of returning the product field with a value of null when
>> the
>> show_product field is false?
>>
>> I can make another field (product_computed) and index that with null where
>> I
>> need but I would like to understand if there is a better approach like
>> putting a function query in the fl and make a computed field.
>>
>> something like:
>>
>> q=*:*&fq=&start=0&rows=10&fl=&qt=&wt=&explainOther=&hl.fl=/*product:(if(show_product:true,
>> product, "")*/
>>
>> that obviously doesn't work.
>>
>> thanks for any help
>>
>> Maurizio
>>
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/Computed-fields-can-I-put-a-function-in-fl-tp3994799.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://lucene.472066.n3.nabble.com/Computed-fields-can-I-put-a-function-in-fl-tp3994799p3995045.html
> To unsubscribe from Computed fields - can I put a function in fl?, click
> here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: Computed fields - can I put a function in fl?

Yonik Seeley-2-2
On Mon, Jul 16, 2012 at 4:43 AM, maurizio1976
<[hidden email]> wrote:
> Yes,
> sorry Just a typo.
> I meant  q=*:*&fq=&start=0&rows=10&qt=&wt=&explainOther=&fl=product:(if(show_product:true,
> product, "")
> thanks

Functions normally derive their values from the fieldCache... there
isn't currently a function to load stored fields (e.g. your "product"
field"), but it's not a bad idea (given this usecase).

Here's an example with the exampledocs that shows IN_STOCK_PRICE only
if the item is in stock, and otherwise shows 0.
This works because price is a single-valued indexed field that the
fieldCache works on.

http://localhost:8983/solr/query?
  q=*:*
&fl=id, inStock, IN_STOCK_PRICE:if(inStock,price,0)

-Yonik
http://lucidimagination.com