You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Vinci <vi...@polyu.edu.hk> on 2008/04/09 08:53:27 UTC

Return the result only field A or field B is non-zero?

Hi all, 

I want to limit the search result by 2 numerical field, A and B, where Solr
return the result only value in field A or B is non-zero. Does it possible
or I need to change the document and schema? or I need to change the schema
as well as the query?

Thank you,
Vinci
-- 
View this message in context: http://www.nabble.com/Return-the-result-only-field-A-or-field-B-is-non-zero--tp16580681p16580681.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Return the result only field A or field B is non-zero?

Posted by Francisco Sanmartin <fr...@olx.com>.
Define "exists"
A. ) Is not declared.
B. ) It is declared, but it has no value. (Empty).

For B) you can use query= -(fieldA:["" TO *]) and it returns all the 
documents with fieldA empty (but declared in the doc)

Pako

Umar Shah wrote:
> hi,
> a related question:
> is there some way where we can specify action based on
>  whether field A exists or not?
>
> -umar
>
> On Fri, Apr 11, 2008 at 8:27 AM, Chris Hostetter <ho...@fucit.org>
> wrote:
>
>   
>> If every document will definitely have a value for both fields, you can
>> do...
>>                q = query
>>        &       fq = -(+fieldA:0 +fieldB:0)
>>
>> ...it's more complicated if some docs don't have any value for one or both
>> fields: if the fields are integers (and not floats) then the easiest thing
>> to do is use some range queries...
>>
>>  fq = fieldA:[* TO -1] fieldA:[1 TO *] fieldB:[* TO -1] fieldB:[1 TO *]
>>
>> ...for floats you would have to get really creative with your set logic
>> ... i'm certain it's possible, i'm just not sure off the top of my head
>> what the fq needs to look like.
>>
>> -Hoss
>>
>>
>>     
>
>   


Re: Return the result only field A or field B is non-zero?

Posted by Umar Shah <um...@wisdomtap.com>.
hi,
a related question:
is there some way where we can specify action based on
 whether field A exists or not?

-umar

On Fri, Apr 11, 2008 at 8:27 AM, Chris Hostetter <ho...@fucit.org>
wrote:

>
> If every document will definitely have a value for both fields, you can
> do...
>                q = query
>        &       fq = -(+fieldA:0 +fieldB:0)
>
> ...it's more complicated if some docs don't have any value for one or both
> fields: if the fields are integers (and not floats) then the easiest thing
> to do is use some range queries...
>
>  fq = fieldA:[* TO -1] fieldA:[1 TO *] fieldB:[* TO -1] fieldB:[1 TO *]
>
> ...for floats you would have to get really creative with your set logic
> ... i'm certain it's possible, i'm just not sure off the top of my head
> what the fq needs to look like.
>
> -Hoss
>
>

Re: Return the result only field A or field B is non-zero?

Posted by Chris Hostetter <ho...@fucit.org>.
If every document will definitely have a value for both fields, you can 
do...
		q = query
	&	fq = -(+fieldA:0 +fieldB:0)

...it's more complicated if some docs don't have any value for one or both 
fields: if the fields are integers (and not floats) then the easiest thing 
to do is use some range queries...

  fq = fieldA:[* TO -1] fieldA:[1 TO *] fieldB:[* TO -1] fieldB:[1 TO *]

...for floats you would have to get really creative with your set logic 
... i'm certain it's possible, i'm just not sure off the top of my head 
what the fq needs to look like.

-Hoss


Re: Return the result only field A or field B is non-zero?

Posted by Vinci <vi...@polyu.edu.hk>.
Hi,

Thank you Underwood.
That still not come up with the solution...doing the boolean operation for
every query (query AND (isAZero OR isBZero) ) if I have the boolean field?
***Adding boolean need largely update the document structure that may not be
preferred...can Solr generate this field for me?

Thank you,
Vinci


Walter Underwood wrote:
> 
> This would be trivial if you also stored boolean fields for
> aiszero and biszero. That would also be fast, I expect.
> 
> wunder
> 
> On 4/8/08 11:53 PM, "Vinci" <vi...@polyu.edu.hk> wrote:
> 
>> 
>> Hi all, 
>> 
>> I want to limit the search result by 2 numerical field, A and B, where
>> Solr
>> return the result only value in field A or B is non-zero. Does it
>> possible
>> or I need to change the document and schema? or I need to change the
>> schema
>> as well as the query?
>> 
>> Thank you,
>> Vinci
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Return-the-result-only-field-A-or-field-B-is-non-zero--tp16580681p16601353.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Return the result only field A or field B is non-zero?

Posted by Walter Underwood <wu...@netflix.com>.
This would be trivial if you also stored boolean fields for
aiszero and biszero. That would also be fast, I expect.

wunder

On 4/8/08 11:53 PM, "Vinci" <vi...@polyu.edu.hk> wrote:

> 
> Hi all, 
> 
> I want to limit the search result by 2 numerical field, A and B, where Solr
> return the result only value in field A or B is non-zero. Does it possible
> or I need to change the document and schema? or I need to change the schema
> as well as the query?
> 
> Thank you,
> Vinci