Django Haystack: Adding custom fields (fl=) to search query string (solr backend) - python

I am trying to use spatial queries to return a resultset sorted by distance which also has the distance information available for each result.
Getting the distance sorting is easy enough with something like this in my SearchForm:
sqs = SearchQuerySet().dwithin('location', self.user_position, D(mi=100)).distance('location', self.user_position).order_by('distance')
The haystack docs say that by adding a call to .distance() it will make distance information available in the results (http://django-haystack.readthedocs.org/en/master/spatial.html#id3) however I took the query string it generates from the logs and pass it to solr through a web browser and it doesn't contain the distance information for each document. Taking a look at the build_search_kwargs method for the solr_backend it appears to be unimplemented. Am I missing something, why would it be in the docs if it's not implemented?
All I have to do to the query to get what I want is add '+dist:geodist()' to the fl parameter as per the solr docs but I can't find a nice way to do it with haystack. Has anyone done this?
Cheers.

Related

LDAP search takes too long

I'm trying to get more than 50.000 records from LDAP (with python-ldap and page control tools).
I have searching filter, which is
(|(field=value_1) (field=value_2)...(field=value_50000)
But this request taking more than 15 minutes. I'm taking 10 attributes from LDAP for these records.
Could you please tell me if is it okay for some large request or I can try to change filter?
You should refine your search base, and make it the closet possible to what you are searching for, for example, instead of querying dc=company,dc=com use ou=people,dc=company,dc=com.
You can also build an index of the field you are searching for, and you can also enable cache for your ldap, and finnally concerning your search filter, if you query the same attribute you can try something like:
&"(field>=MinValue)(field=<MaxValue)"
It's way better the matching every single attribute.

Sorting and Filtering multiple queries of the same collection in Firestore

I'm new on cloud firestore and I'm trying to make queries as efficient as possible but I kind of desperate with an specific one. I would greatly appreciate your help.
This is the situation:
I want to show a project list which that I'm getting from an user field and 2 queries in project entity. The user field let’s called "favorite projects" and it has the projects id that reference those projects on their entity. The other query retrieve me the public projects (==) and the last the private projects where the user is a contributor (array_contains).
I want to sort and filtering the result of the two queries. Is there an option to merge both queries and use sort and filter as a we do with a collection reference?
Thank you for your time, have a nice day!
Based on this and this documentation, I do not believe there is an out of the box solution for joining the results of queries such as the ones described.
You'll need to achieve that within the your code.
For example you can run the first query and store all the data of the document in a map or array. Then use the reference of the other document within the document_reference to make the second query and the third.
Once you have all of them you can do as you please using Python. But getting them ready using a single query or auto-joining the queries seems to not be supported yet.

Django - order existing search results according to user choices

I'm creating a Django (1.8) web application that lets end-users search entries. I've managed to let users get search results according to their input.
However, I also want users to be able to order the search results after the results are returned, according to the user's selection of some choices (e.g. order by distance, order by rating, order by price). I'm having trouble implementing that because I can't figure out the logic behind this.
Could someone please tell me how to implement such feature please? Thank you very much!
The simplest way to do this is .order_by('fieldname').
In your template you could have links to the same page which add GET parameters. In your view check for these parameters and decide how to sort the results.
It'll be somewhat like this
Model.objects.filter(field='value').order_by('sort-criteria')

web2py: how to implement multiple filter for grid?

Can anyone offer suggestions regarding a good way to go about implementing multiple filters for a grid? I'm interested in doing something along the lines of what appears in the following image of Webgrid:
Webgrid
Thanks!
you can set a parameter on some links group to a controller, then on the controller you can process the parameter and in order to this, set a different query to use with it:
grid=SQLFORM.grid(query)
You can use parameters to put into the query or to use different query types...and send it from the views to the controllers ...
Web2py gives you a wide freedom to get anything...
For anyone else interested in doing this, a very good solution was eventually provided at the web2py google group.

Google Apps Engine Datastore Search

I was wondering if there was any way to search the datastore for a entry. I have a bunch of entries for songs(title, artist,rating) but im not sure how to really search through them for both song title and artist. We take in a search term and are looking for all entries that "match." But we are lost :( any help is much appreciated!
We are using python
edit1: current code is useless, its an exact search but might help you see the issue
query = song.gql("SELECT * FROM song WHERE title = searchTerm OR artist = searchTerm")
The song data you work with sounds as a rather static data set (primarily inserts, no or few updates). In that case there is GAE technique called Relation Index Entity (RIE) which is an efficient way to implement keyword-based search.
But some preparation work required which is briefly:
build special RIE entity where you place all searchable keywords
from each song (one-to-one relationship).
RIE stores them in StringListProperty which supports searches like this:
keywords = 'SearchTerm'
(returns True if any of the values in the list keywords matches 'SearchTerm'`)
AND condition works immediately by adding multipe filters as above
OR condition needs more work by implementing in-memory merge from AND-only queries
You can find details on solution workflow and code samples in my blog Relation Index Entities with Python for Google Datastore.
http://www.billkatz.com/2009/6/Simple-Full-Text-Search-for-App-Engine

Categories

Resources