How can I use Solr subquery similar to rdbms subqueries? - solr

I need to run a query in Solr that contains another query as terms of the main query!
Something like this in the RDBMS SQL:
select name from movie
where movie.writer in (
select director from movie where producer = 'XXX'
)
Is there any way to do this is Solr?

Solved.
This is possible using "join" in Solr.
Following is the solution for my answered example:
fl=name&
q={!join from=writer to=director}+producer:XXX
Also a filter query can be added. This filter will affect the result of join and query.
Thanks to Ramzy.

you can try filter, something like this..
q=movie:name
fq=(writer:writer_name AND producer:Producer_name)
also the data that you put into a Solr index is flat or denormalized.
So take the suquery field values and put them in an AND part of the query to Solr.
q=(movie:name AND writer:Writer_name AND producer:Producer_name)

Related

Writing query with where clause in Python NDB

So I have a query that looks like
data = ndb.Key('Account', int(entity_id)).get()
is it possible to add a where clause and filter by other fields
For that, you need to use ndb.query() –
#gaefan comment

SOLR Query similarto NOT IN (LIST)

I have a requirement where we need to fetch the values like
CustomerID NOT IN (LIST OF IDs Indexed) from SOLR Index.
Can anyone suggest how can we achieve this using solr query?.
Use Filter query fq=-id:("id1", id:"id2")
example
http://localhost:8983/solr/collection/select?indent=on&q=querystring&wt=json&fq=-id:("id1", id:"id2")
Here it discards documents with list of IDs mentioned in filter query(fq) parameter
CustomerID:* AND NOT CustomerID:(ID1 OR ID2 OR ... IDn)

SUM and groupBy in solr

How to execute this query:
select SUM(Primary_cause_vaR),
RiskType,market from bil_tos Where skuType='Product' group by RiskType,market;
I've used http://wiki.apache.org/solr/StatsComponent for this:
I see only sum with respective groupBy fields but i want to see RiskType,
market fields also in the result
StatsComponent supports only GROUP BY (stats.facet) on a single field at a time. Using multiple stats.facet parameters has the effect of multiple GROUP BY clauses, if SQL allowed such a thing. What you can do is facet on RiskType, and then for each facet value do another query adding fq=RiskType:<value> and facet on market. It will take a bunch of queries but eventually you'll have the entire result.
Using stats feature particularly stats.facet:
select?q=*:*&fq=fldA:O&rows=0&wt=xml&indent=true&stats=true&stats.field=Amount&stats.facet=fldB

Solr query to return results ordered by 'find in set'

Here is the problem.
I have a solr query like this:
Example:
post_id: ( 31234, 56756, 24352, 78465, 23424 )
And i want to order them , as they are in the query.
Mysql equivalent to this is:
ORDER BY FIND_IN_SET(post_id, '31234, 56756, 24352, 78465, 23424')
I was looking on the Solr sort documentation, googling etc. but nothing.
Is it possible to order articles in Solr like this?
Thanks in advance.
You can only have that kind of Order if you boost your documents accordingly.
for e.g. q=post_id:31234^5 post_id:56756^4 post_id:24352^3 .....

How to use like operator in select query in Apache Solr for java?

I have scenario like to get data which contain some part of that data.
like, i want supplier name from list, i have search with only three character of supplier name.
SQL Syntext : select * from suppliers where supplier_name like '%JM T%'
I need similar query for Apache Solr.
If any help, than its appreciated.
Thanks in Advance
Ashish
In Solr, you can use: supplier_name:*JM T*
But you'll get a little bit problem with white space: solr query with white space
Depends how your solr schema is setup, you could have supplier_name as a field then query like
Supplier_name:"JM T"

Resources