Is it possible to filter my results by boolean and date? (algolia) - algolia

I am trying to filter my algolia results by boolean and date. The problem I have is that the results found do not match the items shown to the user.
Here is what I have so far:
transformItems(items) {
return items.filter(item => {
return (item.enabled === 0 || item.time_of_use_unix < moment().unix()) ? null : item;
});
},
This shows the right items, but does not update my results found number (nbHits).
Is there maybe another way to achieve this?
I found a link which describes something similar, but I don't know how to use it in vue js.
https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-boolean/#applying-a-boolean-filter
If someone could help I would appreciate that.

Solved it with <ais-configure :filters="filters" />

Related

Rows binding in sap.ui.table.Table dynamically

I have made a title depending on variable how it's shown in: Title depending on other variable in SAPUI5
I would like to make the same with rows in sap.ui.table.Table so I tried:
rows="{= ${someData>/infos}.length > 0 ? ${someData>/infos} : ${someData>/result}}"
Whereas someData is an ODataModel (v2).
But got an error:
Uncaught TypeError: Cannot read property 'indexOf' of undefined
Problem
The problem is that you're trying to determine .length from an object. In ODataListBinding (someData>/infos), aggregations are resolved in an object rather than an array. Therefore the syntax can't work. Furthermore, the .length syntax implies that the whole collection is already available on the client-side, contradicting the purpose of sap.ui.table.Table.
Expression binding with .length makes only sense with a client-side JSONModel as mentioned here.
Alternative approach
There are multiple ways to define aggregation binding dynamically, but the most straight-forward solution would be just to access the table control reference and call bindRows dynamically. Something like this:
onInit: function() {
this.loadCountOf("SomeSet", this.bindTableRows.bind(this));
// ...
},
loadCountOf: function(entitySetName, handleCountSuccess) {
const odataModel = /*...*/;
odataModel.read(`/${entitySetName}/$count`, {
success: count => handleCountSuccess.call(this, +count),
});
},
bindTableRows: function(count) {
this.byId("myTable").bindRows({
path: count > 0 ? "/SomeSet" : "/TheOtherSet",
// ...
});
},
API reference: sap.ui.table.Table#bindRows
the errors seem to tell you that either infos or result is undefined. You should check the current value of those arrays.
Anyway, it's not a really good idea to bind table rows like that IMHO.
What's you scenario?

GXT combobox to search from the keyword form anywhere in a word

I am using a GXT ComboxBox to search results from the store.
But by default it search the word which STARTS from the keyword entered,
What i want is to find the words from the store which have the entered keyword any where in that word.
So if i type "M" it only gives me "Maths", but I also want to see "sam" or "lamp"
Any idea how this can be achieved here.
thanks
Starting with GXT v4.0.3 you can use the QueryMatcher interface:
myComboBox.setQueryMatcher((item, query) -> {
String value = getPropertyEditor().render(item);
if (value != null) {
return value.toLowerCase()
.contains(query.toLowerCase());
}
return false;
});
Hope that helps.

MongoDB - Update field with reference of another document

I would like if is possible to update a field of all documents in a collection with a reference to another document. I have tried to do this with the code below:
var project = db.Project.find({slug:"engine"});
db.Activity.update({}, {$set:{'project':DBRef("Project", project._id, "mydb")}});
When I look at the Activity documents, in the "project" field, the result is:
{
_id: ObjectId("..."),
"project": DBRef("Project", undefined, "mydb")
}
Is there a way to do this correctly?
Thanks in advance.
Seems to me you're having a promise callback problem. You can solve it in two ways:
Option one: Put the function depending of your data return inside a callback of the first function, for example:
db.Project.find({slug:"engine"}, function(error, data) {
db.activity.update(...data.Id...);
});
Option two: Wait for the return of the find to be completed:
var project = db.Project.find({slug:"engine"});
project.then(function(error,data) {
db.activity.update(...project.Id...);
});
Both should work. The problem is that when you make the first call, it returns a promise, not the value itself. If you are making confusion on this topic, you can take a look at:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Hope my answer helped you.

Filter by date range

In Ember it is easy to filter an array where you are looking for matching values ( Only return name == "John) What I can't figure out is how to filter with a greater than or less than ( Return all objects whose startDate is before today
In my app I have a collection of deliverables. I want to divide these deliverables into three categories: Due within ten days, Past due, and then the rest.
I found the following example in another SO post, but can't figure out how to use it to accomplish my goal
filterComputed: function() {
return this.get('content').filter(function(item, index, enumerable){
return item.firstName == 'Luke';
});
}.property('content.#each')
You can just do:
this.get('content').filter(function(item){
return item.get('someProperty') > someVar;
});
This should return an array of objects within your defined date range. Should work in Ember ^2.x.
filterComputed: computed('content.#each', 'startDate', 'endDate', function() {
return this.get('content').filter(function(item) {
var contentDate = item.get('date'); // expecting item to have a date property
return contentDate > this.get('startDate') && bookingDate < this.get('endDate');
});
})
With ES6 you could even do something like this:
filterComputed: computed('content.#each', 'startDate', 'endDate', function() {
return this.get('content').filter(item => item.get('date') > this.get('startDate') && item.get('date') < this.get('endDate'));
})
If you have a simpler requirement, computed.filterBy() might be right for you. https://emberjs.com/api/classes/Ember.computed.html#method_filterBy
Also helpful: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

KendoUI Autocomplete paging issue

I have a textbox bound to KendoUI autocomplete widget. The JS code looks like this:
var dataSourceImeSearch = {
type: "json",
transport: {
read: {
url: "#Url.Action("ImeSearch")",
contentType: "application/json; charset=utf-8",
type: "POST"
},
parameterMap: function (data, type) {
if (type == "read") {
if (data.filter) {
data = $.extend({ sort: null, filter: data.filter.filters[0] }, data);
} else {
data = $.extend({ sort: null, filter: null }, data);
}
return JSON.stringify(data);
} else {
return JSON.stringify({ model: data });
}
}
},
batch: false,
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
schema: {
errors: "Errors",
data: "Data",
total: "TotalRecordCount",
model: myModel
},
error: function (e) {
if (e.errors) {
alert(e.errors);
}
}
};
$("#Ime").kendoAutoComplete({
dataTextField: "PunoIme",
filter: "contains",
minLength: 3,
dataSource: dataSourceImeSearch
});
I am experiencing a weird thing here. Autocomplete is working in terms that when I type the third character it runs to the server and gets JSON data back from there and shows first ten results. The thing is that this textbox is searching large datasets, so for some queries with say 4 characters result set can be more than 1000 items. For some reason the widget is not figuring out that there are more than 10 results and when I scroll down in the autocomplete dropdown which gets shown, it will not fire any search for a second page and so on. You can see that the serverPaging for data source is set to true, but this does not help.
Any help is appreciated. Thank you.
I found out after posting this question that Autocomplete widget does not allow paging by design. This was explained in the KendoUI forums by some Kendo employee as an example of poor UX (if you have autocomplete that needs paging). I would argue that, since in my opinion, the first use case of the autocomplete would be in case of a search of a person, and here I am doing exactly that. The only problem is that if you search by person's second name you can end up with hundreds of results after first 3 or 4 characters and you really need paging for that. If the Kendo people think that this is a case of a bad UX, this should be clearly mentioned in the Autocomplete documentation, and I could really not find any mentioning of it at a single place, and one would think that it might be a good idea to mention something like this to the people so that they don't have to waste all day trying to figure out what went wrong.
In my opinion one of the worst use case examples at all demos at KendoUI web demo pages is the Shared DataSource example, where if you type in 'ch' in the autocomplete textbox in the top, you will end up with 10 results in autocomplete, but 14 in the datagrid bellow. It really strikes me as stupid that nobody in Kendo sees this behavior as odd.
So my answer to my own question would be the following: DO NOT use autocomplete, except in some really really simple use case (I can't really think of a single one that would make sense). I ended up making a whole search form with 5 textboxes and search button in case where I hoped that I was going to be able to use 2 textboxes (one with autocomplete) and a search button.
You have set pageSize:10, which means that only 10 records are returned to the AutoComplete and its dataSource contains only 10 elements, I am afraid that automatic paging is not implemented by default