I have model which looks like this:
class Example (db.Model) :
name = db.StringProperty()
tags = db.StringListProperty()
I first query for a tag to get the list of entities which have them:
results = Example.all().filter("tags =", tagSearch).fetch(100)
This gives me a list of entities containing the "tagSearch" in their "tags" list.
Here is how a sample of the result entities would look like:
entityA = [tagSearch, m, n, o, ....]
entityB = [a, b, c, tagSearch, ... ]
entityC = [a, tagSearch, a, ,a ,x ....... ....]
I want to sort all the entities in the result set based on the position of the item tagSearch in them, in descending order.
basically - entityA, entityC, entityB
How do I do this? note I am running this on appengine ...
also assumption given than tagSearch will occur only once in any list.
Any help will be highly appreciated.
You won't be able to sort these in the query, as far as I know. So the only alternative is to fetch them all and sort them accordingly in your code.
This may not be feasibly performant depending on the number of entities you'd have to return, so you may want to limit the entities in some other way before fetching.