generate field name in query

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

generate field name in query

xdzgor1
Hi - is it possible to create a query (or fq) which generates the field to search on, based on whether or not the document has that field?

Eg. Search for documents with prices in the range 100 - 200, using either the field "price_owner_float" or "price_customer_float" (if a document has a field "price_owner_float" then use that, otherwise use the field "price_customer_float").

This gives a syntax error:
fq=if(exists(price_owner_float),price_owner_float,price_customer_float):[100 TO 200]

Thanks,
Peter


Reply | Threaded
Open this post in threaded view
|

Re: generate field name in query

Rick Leir-2
Peter
The common setup is to use copyfield from all your fields into a 'grab bag' containing everything, and then to search on it alone. Cheers -- Rick

On August 2, 2017 7:31:10 AM EDT, Peter Kirk <[hidden email]> wrote:

>Hi - is it possible to create a query (or fq) which generates the field
>to search on, based on whether or not the document has that field?
>
>Eg. Search for documents with prices in the range 100 - 200, using
>either the field "price_owner_float" or "price_customer_float" (if a
>document has a field "price_owner_float" then use that, otherwise use
>the field "price_customer_float").
>
>This gives a syntax error:
>fq=if(exists(price_owner_float),price_owner_float,price_customer_float):[100
>TO 200]
>
>Thanks,
>Peter

--
Sorry for being brief. Alternate email is rickleir at yahoo dot com
Reply | Threaded
Open this post in threaded view
|

Re: generate field name in query

xdzgor1
Rick Leir-2 wrote
> Peter
> The common setup is to use copyfield from all your fields into a 'grab
> bag' containing everything, and then to search on it alone. Cheers -- Rick
>
> On August 2, 2017 7:31:10 AM EDT, Peter Kirk &lt;

> pk@

> &gt; wrote:
>>Hi - is it possible to create a query (or fq) which generates the field
>>to search on, based on whether or not the document has that field?
>>
>>Eg. Search for documents with prices in the range 100 - 200, using
>>either the field "price_owner_float" or "price_customer_float" (if a
>>document has a field "price_owner_float" then use that, otherwise use
>>the field "price_customer_float").
>>
>>This gives a syntax error:
>>fq=if(exists(price_owner_float),price_owner_float,price_customer_float):[100
>>TO 200]
>>
>>Thanks,
>>Peter
>
> --
> Sorry for being brief. Alternate email is rickleir at yahoo dot com


Thanks, but I don't really think a general copy-field is what I want. I want
to specifically search for particular values in named fields.

For example:
if the document has a "field1" then use "field1:[1 TO 100]"; but if there is
no "field1", then check if there is a "field2"; if there is a "field2" then
use "field2:[1 TO 100]; but if there is no "field2", then use "field3:[1 TO
100].

Something like:
?q=*:*&fq=if(exists(field1),field1:[1 TO 100],if(exists(field2),field2:[1 TO
100], field3:[1 TO 100]))


But is this does not work.
Is it even possible?




--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Reply | Threaded
Open this post in threaded view
|

Re: generate field name in query

Hendrik Haddorp
You should be able to just use
price_owner_float:[100 TO 200]  OR price_customer_float:[100 TO 200]

If the document doesn't have the field the condition is false.

On 12.09.2017 23:14, xdzgor1 wrote:

> Rick Leir-2 wrote
>> Peter
>> The common setup is to use copyfield from all your fields into a 'grab
>> bag' containing everything, and then to search on it alone. Cheers -- Rick
>>
>> On August 2, 2017 7:31:10 AM EDT, Peter Kirk &lt;
>> pk@
>> &gt; wrote:
>>> Hi - is it possible to create a query (or fq) which generates the field
>>> to search on, based on whether or not the document has that field?
>>>
>>> Eg. Search for documents with prices in the range 100 - 200, using
>>> either the field "price_owner_float" or "price_customer_float" (if a
>>> document has a field "price_owner_float" then use that, otherwise use
>>> the field "price_customer_float").
>>>
>>> This gives a syntax error:
>>> fq=if(exists(price_owner_float),price_owner_float,price_customer_float):[100
>>> TO 200]
>>>
>>> Thanks,
>>> Peter
>> --
>> Sorry for being brief. Alternate email is rickleir at yahoo dot com
>
> Thanks, but I don't really think a general copy-field is what I want. I want
> to specifically search for particular values in named fields.
>
> For example:
> if the document has a "field1" then use "field1:[1 TO 100]"; but if there is
> no "field1", then check if there is a "field2"; if there is a "field2" then
> use "field2:[1 TO 100]; but if there is no "field2", then use "field3:[1 TO
> 100].
>
> Something like:
> ?q=*:*&fq=if(exists(field1),field1:[1 TO 100],if(exists(field2),field2:[1 TO
> 100], field3:[1 TO 100]))
>
>
> But is this does not work.
> Is it even possible?
>
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html