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 Utkarsh Sengar <ut...@gmail.com> on 2013/10/17 22:16:31 UTC

Check if dynamic columns exists and query else ignore

I trying to do this:

if (US_offers_i exists):
   fq=US_offers_i:[1 TO *]
else:
   fq=offers_count:[1 TO *]

Where:
US_offers_i is a dynamic field containing an int
offers_count is a status field containing an int.

I have tried this so far but it doesn't work:

http://solr_server/solr/col1/select?
q=iphone+5s &
fq=if(exist(US_offers_i),US_offers_i:[1 TO *], offers_count:[1 TO *])

Also, there is a heavy performance penalty for this condition? I am
planning to use this for all my queries.

-- 
Thanks,
-Utkarsh

Re: Check if dynamic columns exists and query else ignore

Posted by Utkarsh Sengar <ut...@gmail.com>.
Bumping this one, any suggestions?
Looks like if() and exists() are meant to solve this problem, but I am
using it in a wrong way.

-Utkarsh


On Thu, Oct 17, 2013 at 1:16 PM, Utkarsh Sengar <ut...@gmail.com>wrote:

> I trying to do this:
>
> if (US_offers_i exists):
>    fq=US_offers_i:[1 TO *]
> else:
>    fq=offers_count:[1 TO *]
>
> Where:
> US_offers_i is a dynamic field containing an int
> offers_count is a status field containing an int.
>
> I have tried this so far but it doesn't work:
>
> http://solr_server/solr/col1/select?
> q=iphone+5s &
> fq=if(exist(US_offers_i),US_offers_i:[1 TO *], offers_count:[1 TO *])
>
> Also, there is a heavy performance penalty for this condition? I am
> planning to use this for all my queries.
>
> --
> Thanks,
> -Utkarsh
>



-- 
Thanks,
-Utkarsh

Re: loading djvu xml into solr

Posted by sara amato <sa...@willamette.edu>.
Ah, thanks for the clarification - I was having a serious misunderstanding!  (As you can tell I'm newly off the tutorial and blundering ahead...)

On Oct 18, 2013, at 2:22 PM, Upayavira wrote:

> 
> 
> On Fri, Oct 18, 2013, at 10:11 PM, Sara Amato wrote:
>> Does anyone have a schema they'd be willing to share for loading djvu xml
>> into solr?  
> 
> I assume that djvu XML is a particular XML format? In which case, there
> is no schema that can do it. That's not how Solr works.
> 
> You need to use the XML format expected by Solr. Or, you can add
> tr=xxxx.xsl to the URL, and use an XSL stylesheet to transform your XML
> into Solr's XML format.
> 
> The schema defines the fields that are present in the index, not the
> format of the XML used.
> 
> Upayavira


Re: loading djvu xml into solr

Posted by Upayavira <uv...@odoko.co.uk>.

On Fri, Oct 18, 2013, at 10:11 PM, Sara Amato wrote:
> Does anyone have a schema they'd be willing to share for loading djvu xml
> into solr?  

I assume that djvu XML is a particular XML format? In which case, there
is no schema that can do it. That's not how Solr works.

You need to use the XML format expected by Solr. Or, you can add
tr=xxxx.xsl to the URL, and use an XSL stylesheet to transform your XML
into Solr's XML format.

The schema defines the fields that are present in the index, not the
format of the XML used.

Upayavira

loading djvu xml into solr

Posted by Sara Amato <sa...@willamette.edu>.
Does anyone have a schema they'd be willing to share for loading djvu xml into solr?  
 

Re: Check if dynamic columns exists and query else ignore

Posted by Utkarsh Sengar <ut...@gmail.com>.
Thanks Chris! That worked!
I overengineered my query!

Thanks,
-Utkarsh


On Fri, Oct 18, 2013 at 12:02 PM, Chris Hostetter
<ho...@fucit.org>wrote:

>
> : I trying to do this:
> :
> : if (US_offers_i exists):
> :    fq=US_offers_i:[1 TO *]
> : else:
> :    fq=offers_count:[1 TO *]
>
> "if()" and "exist()" are functions, so you would have to explicitly use
> them
> in a function context (ie: {!func} parser, or {!frange} parser) and to use
> those nested queries inside of functions you'd need to use the "query()"
> function.
>
> but nothing about your problem description suggests that you really need
> to worry about this.
>
> If a document doesn't contain the "US_offers_i" then US_offers_i:[1 TO *]
> won't match that document, and neither will US_offers_i:[* TO *] -- so you
> can implement the logic you describe with a simple query...
>
> fq=(US_offers_i:[1 TO *] (offers_count:[1 TO *] -US_offers_i:[* TO *]))
>
> Which you can read as "Match does with 1 or more US offers, or: docs that
> have 1 or more offers but no US offer field at all"
>
> : Also, there is a heavy performance penalty for this condition? I am
> : planning to use this for all my queries.
>
> Any logic that you do at query time, which can be precomputed into a
> specific field in your index will *always* make the queries faster (at the
> expense of a little more time spent indexing and a little more disk used).
> If you know in advance that you are frequently going to want to ristrict
> on this type of logic, then unless you index docs more offten then you
> search docs, you should almost certainly index as "has_offers" boolean
> field that captures this logic.
>
>
> -Hoss
>



-- 
Thanks,
-Utkarsh

Re: Check if dynamic columns exists and query else ignore

Posted by Chris Hostetter <ho...@fucit.org>.
: I trying to do this:
: 
: if (US_offers_i exists):
:    fq=US_offers_i:[1 TO *]
: else:
:    fq=offers_count:[1 TO *]

"if()" and "exist()" are functions, so you would have to explicitly use 
them 
in a function context (ie: {!func} parser, or {!frange} parser) and to use 
those nested queries inside of functions you'd need to use the "query()" 
function.

but nothing about your problem description suggests that you really need 
to worry about this.

If a document doesn't contain the "US_offers_i" then US_offers_i:[1 TO *] 
won't match that document, and neither will US_offers_i:[* TO *] -- so you 
can implement the logic you describe with a simple query...

fq=(US_offers_i:[1 TO *] (offers_count:[1 TO *] -US_offers_i:[* TO *]))

Which you can read as "Match does with 1 or more US offers, or: docs that 
have 1 or more offers but no US offer field at all"

: Also, there is a heavy performance penalty for this condition? I am
: planning to use this for all my queries.

Any logic that you do at query time, which can be precomputed into a 
specific field in your index will *always* make the queries faster (at the 
expense of a little more time spent indexing and a little more disk used).  
If you know in advance that you are frequently going to want to ristrict 
on this type of logic, then unless you index docs more offten then you 
search docs, you should almost certainly index as "has_offers" boolean 
field that captures this logic.


-Hoss