filter data using dropdown? - angularjs

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.

Related

Using both AND and OR Filtering options - Material UI DataGrid/XGrid

I have a big table of data and have created some Select components to show all of the unique options in that column.
If my data was about supermarkets, I want to be able to see all in America. So America is selected and it works well so far. Then I want to see all Supermarkets that stock Bananas in America, so from the location column America is selected, and in the fruits, column bananas are selected. Still working well.
If I want to see all Supermarkets in America that stock Bananas or Apples, we get problems.
How can I apply the AND to separate columns, but the OR to filters of the same column?
Instead of trying to use 2 different link operators, you can achieve what you need using the right combination of filter operator and link operator.
There's no way to do that using the default filter panel. You'll have to create and manually pass a filter model to the grid.
Steps to get it done:
Use the isAnyOf filter operator.
Provide the filter value as an array of values.
Use the AND link operator.
Manually pass the custom filter model created to the grid.
Note:
Your UI should contain some sort of dropdowns for each column with multiple checkboxes for all the choices that can be added to the filter value array.
So in your case, a dropdown for countries, and another for fruits.
The filter Model should look something like this:

Amazon like refined filtering in solr

We need to implement drill down search like Amazon.
If any supplier is selected then,
currently it disabled rest of suppliers as solr facet only returns that selected filter.
query: supplier:supplierId
Though above query retuns multiple Screen Color/Screen Size, but on further selection, only the selected element is returned per filter section.
Any help to make it work like Amazon.com 's refined filtering will be much appreciated.
To provide multi-select faceting, you need to tag the filter involved so that you can exclude it when faceting on the corresponding field. This can be achieved using both the tag and ex local parameters.
Solr Ref Guide - Tagging and Excluding Filters :
To implement a multi-select facet for a given field, a GUI may want to still
display the other field values and their associated counts, as if
the corresponding filter constraint had not yet been applied.
To return counts for the field values that are currently not selected,
tag filters that directly constrain the field, and exclude those
filters when faceting on it.
For example, for a query that would originally look like :
q=mainquery&fq=supplier:supplierId&facet=true&facet.field=supplier
You would do the following :
q=mainquery&fq={!tag=sup}supplier:supplierId&facet=true&facet.field={!ex=sup}supplier

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.

Google Data store UI can't use descending index

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.

Resources