Google Data store UI can't use descending index - google-app-engine

I have an app that uses google's datastore.
I have set up an index that uses two properties of some entity, the first one is ascending and the second one is descending.
When I try to filter by the first property (equals some value) and sort descending by the second I get an error saying that I don't have an appropriate index.
But it seems to me that its because when I click the second column it tries to sort ascending as a default and this is what failes.
Is there a way to ask the UI to filter descending (without going through ascending first) ?

You can use "Query by GQL tab" to test if its UI only problem
By default datastore creates 2 single property indexes (asc, desc) for each column, so try to apply required order first and then apply filter.

Related

Apachesolr search result sorting

I'm trying to change sorting from apache Solr query.
for example bundle type: story, videogallery and category_management are indexed.
I wanted to show all results related to bundle type: category_management on top.
See attached screenshot:
Please help me to user Solr filter to sort my result.
The easiest way is to apply a boost to any entry that matches your requirement:
&bq=bundle:category_management^50
The weight - 50 - may have to be adjusted to get the result you want. This is faster than sorting by a function.
This will also still keep relevancy score inside each set of documents, compared to sorting by a function or adding a priority field for sorting.
If you want to actually apply a sort on multiple fields instead, you can first sort by a function that returns 1 for values that match and 0 for values that doesn't. Something like:
sort=if(termfreq(bundle,'category_management'),1,0),ds_changed desc

Sorting by date with AppEngine search API

I have documents with a contents TextField and a date DateField. I am trying to fetch the most recent documents.
A regular search with 'date > epoch' seems to already sort the
results by date. Is that an expected behavior?
When I try to explicitly sort with SortExpression the results are not even sorted in any particular order (except on the dev server where it seems to work as well).
I am using the following code:
index.search(search.Query(query_string='date > epoch',
options=search.QueryOptions(
sort_options=search.SortOptions(
expressions=[search.SortExpression(
expression='date',
direction=search.SortExpression.DESCENDING,
default_value='1970-01-01')])))
What is the right way to do that?
According to the documentation, all documents are sorted by their rank unless you specify a different sorting option. And a document rank is set to the time when it was added to the index, again, unless you specify a different rank.
If this is your desired behavior, there is no need to add a date field and sort by it.
When you filter by a field your are forcing to use index and as side result the output will be sorted by that field.
https://cloud.google.com/appengine/docs/python/search/options
When you call the search() method using a query string alone, the
results are returned according to the default query options:
Documents are returned sorted in order of descending rank
Documents are returned in groups of 20 at a time
Retrieved documents contain all of their original fields
Don't know why it does not work with explicit sorting options.

Getting Solr Elevated Results on top of Sorted by field Results

We are using Solr 5. We are able to apply sorting on display order field in to Solr query and it works fine. We have certain results which are elevated and will always want them first. If we remove the sorting, the elevation works fine. However, we are unable to get both of them work together.
We want to first list elevated results in the top and then other results based on the display order field.
However, we are unable to find how to do this. Any help will be appreciated.
Thanks in advance.
QueryElevation respects the sort parameter by default, but you can override this by giving the forceElevation parameter:
forceElevation
By default, this component respects the requested sort parameter: if the request asks to sort by date, it will order the results by date. If forceElevation=true (the default), results will first return the boosted docs, then order by date.

filter data using dropdown?

I have an array of objects which are just items. I also have a dropdown which I would like to use to allow the user to filter by price or rating however on page load there should be no filtering.
How do I map item data to filter based on the current select option?
I have a plunkr to get started: LINK
First and foremost, your select values are ambiguous. They contain values that can filter AND sort the entries - Separate the two since they are two different functionality.
Next, you need to define a custom Filter which will filter the data based on the rating selected. For this, you enhance the filtering criteria with the "Rating" property to associate the rating selected with a rating value.
Finally, associate the sorting with a predicate and a reverse value - the predicate determines the property / column to determine for the sort (price in your case) while the reverse determines the ascending / descending nature of the sort.
The entire code can be found here - http://plnkr.co/edit/n7TebC?p=preview
I have updated the plunkr and introduced comments so let me know if you do not understand a code.

solr query without order

I have a solr index with the unique field as "id".
I have a ordered set of ids, using which I would like to query Solr. But I want the results in the same order.
so for example if i have the ids id = [5,1,3,4] I want the results displayed in solr in same order.
I tried http://localhost:8983/solr/select/?q=id:(5 OR 1 OR 3 OR 4)&fl=id, but the results displayed are in ascending order.
Is their a way to query solr, and get results as I mentioned?
I think you can't,
The results appear in the order they are indexed unless you specify a default sort field or the explicit sort field/order.
You can add another field to keep the initial sort order. You then can sort=field asc to retrieve the data in the original order.
The simple way is to query solr and sort the results in codes of yourself.

Resources