Faceting on Search multiple indexes feature from Algolia - javascript

I am running a query on more than one of my indexes (by using this and everything works fine. Now, I want to implement a faceted search using such functionality (this) but I am not being able to do it since I don't instantiate an index per each query I want to run. I tried to find some information out there about this but I was not able to find a solution for my problem and I want to avoid instantiating multiple indexes. Ideas?
This is a piece of the code I am using to search with multiple queries:
query.push({
indexName: 'My Index',
query: 'My Query', //I would like to use here something like 'NOT customAttr:"my value"'
params: {
hitsPerPage: 5
}
});
client.search(query, function searchDone(){});

Related

Sequelize run hook once after include

I'm new to Sequelize and try to achieve the following:
Assume I have a very simple database with 3 Models/Tables:
Person, Group and Category.
Person has a Many-To-One relation to Group (1 Person can be in 1 Group, 1 Group holds multiple people) & Group has a Many-To-One relation to Category (1 Group has 1 Category, 1 Category can be applied to multiple Groups).
Because I don't want to save the whole Category in my database, but only a short string, I have a mapper in the backend in my app.
Let's say my Category-Mapper looks like this:
//category.mapper.js
module.exports = Object.freeze({
cat1: "Here is the String that should be sent to and displayed by the FrontEnd",
cat2: ".....",
});
So basically, in my database I save "cat1" as the category and every time I get one or more Categories via Sequelize from the database, I want to go into my mapper, resolve the short string to the long string and send it to the Frontend, so I wrote the following code:
//category.model.js
const categoryMapper = require("../mapper/category.mapper");
Category.afterFind((models) => {
if(!Array.isArray(models)) {
models = [models];
}
models.forEach(model => {
model.name = categoryMapper[model.name];
});
});
This works great when I call Category.findAll()..., but does not trigger when I include the Category as in this example:
Group.findAll({
include: [Category]
})
There is this rather old GitHub Issue referencing this behavior, where someone published some code to make sure the hooks run on include. See here.
I tried implementing the referenced code into my project, but when I do, the hook for Category runs twice in my following code:
Person.findAll({
include: [{
model: Group,
include: [Category]
}]
})
My assumption is, that, with the code from the GitHub-Issue comment, my hook gets triggered every time the relationship is detected and the code runs. Therefore the hook runs once after including Group, because Group has a relationship to Category and a second time when Category is actually included, which breaks my mapping function because the second time it tries to resolve the long string, which doesn't work.
I'm looking for a solution that basically runs my hooks once and only once, namely when the actual include for my model triggers, regardless of on what level the include happens.
Sorry for the lengthy post, but I did not find any solution to my problem online, but don't believe what I am trying to achieve is very exotic or specific to my project only.
If there is a better solution I am not seeing, I'm open to suggestions and new approaches.
Thanx in advance!

Is it possible to reset specific item in Apollo Client Cache?

I have a query which uses fetchMore and the relayPagination which works fine for lazy loading when using the variables page and perPage, the issue now is I'm trying to refresh the query whenever i update the other variables for filtering like date and type which values can be either debited or credited. It fetches the data, but then appends the incoming data to apollo cache instead of replacing the old data with the new one.
for example in this sample typePolicy
PaginatedBooks: {
fields: {
allBooks: {
merge: relayPagination()
}
}
}
AllProducts: {
// Singleton types that have no identifying field can use an empty
// array for their keyFields.
keyFields: [],
},
I only want to reset PaginatedBooks
I've tried use fetchPolicy of no-cache but this stops pagination and fetchMore from working as i can't merging existing and incoming data. I opted to use client.resetStore(): https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.resetStore
but this also refetches other active queries and causes the ui to flicker. So far looking through the documentation and github repo I can't seem to find anything or anyone who has tried to do something similar, so I'm hoping I can get some insight and probably be offered a better solution. Thanks in advance

Updating Multiple Documents In MongoDB Based on ID

So I've seen this question asked before, but when I tried the solution myself it didn't seem to work. Update multiple documents by id set. Mongoose
Based on the solution above, I wrote this code:
listOfParticipant = [ "5f50a1df63fe0000ed98b393", "5f69cc7cda1d549f9edcc8bb","5f3207204450b32620449657","5f3207204450b32620449657", "5f39585030027a3d57f0cc0e", "5e719e4715c7865bcb00c820", "5f32d0ab59eccf22d2e2f29f" ],
User.update( {_id: {$in: listOfParticipant}},
{$addToSet: {
userNotification: notification
}
},
{multi: true}
)
But it doesn't seem to work, could anyone help me out in finding out why?
So this query is correct. The reason it wasn't working is because I was trying to chain it with another MongoDB call. I was trying to use it inside the callback function when I updated another MongoDB collection. Once I made this into its own separate function, it worked just fine!

Search and replace in MongoDB collection

I have a mongo collection that contains a field called "url", storing an url.
Some of those urls have an extra parameter that bothers me, "id=<>" where <> can have any size
Can i do this in a update operation or do i need to write a script that will iterate and replace?
db.find({{"url": /.&id=.*/ }}).update(???)
Your best bet is going to be to explore use of the "multi" parameter in conjunction with field update parameters, as described at these locations on the MongDB website.
http://docs.mongodb.org/manual/reference/operator/update-field/
http://docs.mongodb.org/manual/reference/method/db.collection.update/#multi-parameter
An example is provided here:
http://docs.mongodb.org/manual/reference/method/db.collection.update/#example-update-multi
The issue is that you won't be able to implement any sort of "capturing group" functionality that just gets rid of the "id" parameter for each document though. There is a ticket open on MongoDB's jira account though detailing this behavior (currently in unresolved state):
https://jira.mongodb.org/browse/SERVER-9159
Try this to find documents using this regEx and then do update accordingly.
db.find({
"url": /id=\<.+\>/
}, function(err, result) {
//your code
})

How would I add a query filter to the Iteration Tracking Board?

So I have the source code for the Iteration Tracking Board on Rally. All I want to do is to add a query filter that is similar to the Portfolio Hierarchy app or the Portfolio Kanban Board.
If this is possible, I think that I may need to add it in the javascript code as a plugin and I was wondering how that should be coded.
Is this correct? Or can I not even add the filter as a plugin because it is not defined as one in Rally?
For some quick background, here is a guide on working with settings in apps: https://help.rallydev.com/apps/2.0rc2/doc/#!/guide/settings
This is a 2 parter. First, you'll need to add the query settings field to your app. Since this field is commonly used across apps there is a handy preconfigured on you can just reference by type:
getSettingsFields: function() {
var fields = this.callParent(arguments);
//...
//existing code omitted for brevity
//...
fields.push({type: 'query'});
return fields;
}
Then you'll need to actually use that setting to filter the data shown. Add the following to the cardBoardConfig object:
storeConfig: {
filters: this.getSetting('query') ?
[Rally.data.QueryFilter.fromQueryString(this.getSetting('query'))] : []
}

Categories