Writing query with where clause in Python NDB - google-app-engine

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

Related

How can I use Solr subquery similar to rdbms subqueries?

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)

SOLR AND clause in q object

I need to query SOLR index using a WHERE clause -
When I try with AND clause its not working
NOT WORKING
category:2 AND -document_type:category
WORKING
category:2 -document_type:category
Which is the correct syntax?
You could try to pass -(document_type:category) as a filter query (fq=-(document_type:category)). Should work that way and is also faster because of optimized caches on filter queries.
Also tested your specific case, but it also works for me in a regular query.

Search with multiple parameters in solr

Currently I having the query like this
q=mysearchparameters
It is working fine, and I think it will search for this keyword in all the fields, now I want to retrieve data only based in some specific field like this
q=name:'somename'+specialization:'somespecialization'
is it possible to query like, here I getting some unexpected datas for my second query.
You can have multiple queries, ANDed together, like this:
q=name:somename AND specialization:somespecialization
or ORer together like this:
q=name:somename OR specialization:somespecialization
Or you can use filter queries to AND them together:
q=*:*&fq=name:somename&fq=specialization:somespecialization
I won't get into queries versus filter queries as it is covered better elsewhere:
SOLR filter-query vs main-query
in order to perform a multicriteria request, you'd better do :
q=*:*
fq= name:*somename*
fq= specialization:*specializstr*
http req example : http://localhost:8983/solr/datav6/select?q=*%3A*&fq=data%3A*carlos*%5E5&fq=entity%3Aemployee&wt=json&indent=true
it' saffer on the results, faster on execution and consumes less ram.
enjoy and give me some feedback please! :)

Multiple Filter Queries with OR operation in Solr

I need to define multiple Filter Queries in my query but with OR operation.
Imagine that there are fq1, fq2 and fq3. Now I would like my final filter query to be :
fq=fq1 AND fq2 OR fq3
Is there any way to handle it in Solr?
It seems that now SOLR (>4.5) supports these type of queries, i.e.
fq=(field1:value1 OR field2:value2)
This is not possible in Solr. It would be great if you could define your filter queries and then separately specify the boolean logic that should be applied between them.
A few years ago I created a Jira issue hoping to see this get added.
You can do something like this:
fq=fieldA:(valueA OR valueB) OR fieldB:valueC
+fq:fq1 +(fq2:fq2 fq3:fq3) <-- if default query filter type is OR

Order by an expression in Solr

In SQL you can order by an expression like:
SELECT * FROM a
ORDER BY CASE WHEN a.Category = 20 THEN 1 ELSE 0 DESC
so records who have Category = 20 are on top.
Is this possible in Solr?
Solr doesn't have an if/then (at least not until 4.0), but it does have a map function and the ability to use function queries in your sort. You can probably use something like this in your sort to achieve what you're after:
?q=*&sort=map(category,20,20,case,0),score desc
(untested)
Here is a thread that talks about using map for an if statement.
I've accepted hross's answer, but it's also possible to do something like this in Solr 1.3 and up, using:
/select?q={!func}map(Category,20,20,1,0)&sort=score desc
The cool thing is that you can still sort on other fields, so:
&sort=score desc, name asc
If you are using the dismax request handler, then you can use boost queries in a similar fashion. http://wiki.apache.org/solr/DisMaxQParserPlugin#bq_.28Boost_Query.29 Note that this doesn't function exactly like the your SQL example, but you can achieve the same results with it.

Resources