阿尔及利亚重复
Algolia Duplicates
我在让 Algolia 正常工作时遇到了一些麻烦。我正在使用 NodeJS 并试图在我的数据库和 Algolia 之间进行一些同步,但由于某种原因似乎随机弹出大量重复项。
如您所见,在某些情况下,会弹出两个不同的条目,它们的数据完全不同,主题名称除外。我不是 运行 其他任何地方的 add-to-algolia 代码,并且 UUID 已关闭,因为我输入的条目前面有 "topic-"。
function loadNewTweets(){
console.log("Checking...");
var tweets;
var topics;
var referenceTopics;
Promise.all([
//stuff
])
.then(function(data){
topics = [
//data
]
return Promise.each(topics, function(topic, index){
return new Promise(function(res,rej){
Promise.all([
//things
])
.then(function(r){
var id = 'topic-'+uuid.v4();
if(!topicDB){
var obj = {
//data
}
console.log("Adding", topic.topic, "to topic DB + Algolia");
return new Promise(function(res,rej){
var dbInstance;
Database.models.Topic.create(obj)
.then(function(topic){
dbInstance = topic;
return Search.addData('topics', [dbInstance])
})
.then(function(content){
dbInstance.algoliaId = content.objectIDs[0];
return dbInstance.save(['algoliaId']);
})
.then(function(){
return res();
})
})
}
})
.then(function(){
return res();
})
})
})
})
.then(function(){
return Database.models.Topic.findAll({})
})
.then(function(topicsDB){
//If a topic is in the database, but not the topics array.
//Loop through each database entry.
Promise.each(topicsDB, function(topic){
var del = true;
//Go through topics array
for(var i=0;i<topics.length;i++){
//If a topic in the array matches a database entry, dont remove it.
if(topics[i].topic == topic.topic){
del = false;
}
}
//If no entry was found in the array for this topic in the database, remove it from the database and Algolia.
if(del){
console.log("Deleting", topic.topic, "from topic DB + Algolia", topic.algoliaId);
Search.delete('topics', [topic.algoliaId])
.then(function(){
topic.destroy();
})
}
})
})
}
是否缺少某种选项?任何帮助将不胜感激。
编辑:副本与原件之间似乎存在某种关系,但我仍然无法弄清楚是什么原因造成的。
(见谅吧)
所以这很尴尬。
我忘记了一个也在为索引做出贡献的临时服务器。
存在重复,因为您没有使用 [objectID][1] 来唯一标识您的记录。通常主键作为 objectID 可以正常工作。如果你不指定一个,Algolia 会自动分配一个,这意味着很难没有重复。
{
name: 'some name',
objectID: 'the id of the data in my database'
}
文档中有示例:https://www.algolia.com/doc/api-reference/api-methods/save-objects/#examples
我在让 Algolia 正常工作时遇到了一些麻烦。我正在使用 NodeJS 并试图在我的数据库和 Algolia 之间进行一些同步,但由于某种原因似乎随机弹出大量重复项。
如您所见,在某些情况下,会弹出两个不同的条目,它们的数据完全不同,主题名称除外。我不是 运行 其他任何地方的 add-to-algolia 代码,并且 UUID 已关闭,因为我输入的条目前面有 "topic-"。
function loadNewTweets(){
console.log("Checking...");
var tweets;
var topics;
var referenceTopics;
Promise.all([
//stuff
])
.then(function(data){
topics = [
//data
]
return Promise.each(topics, function(topic, index){
return new Promise(function(res,rej){
Promise.all([
//things
])
.then(function(r){
var id = 'topic-'+uuid.v4();
if(!topicDB){
var obj = {
//data
}
console.log("Adding", topic.topic, "to topic DB + Algolia");
return new Promise(function(res,rej){
var dbInstance;
Database.models.Topic.create(obj)
.then(function(topic){
dbInstance = topic;
return Search.addData('topics', [dbInstance])
})
.then(function(content){
dbInstance.algoliaId = content.objectIDs[0];
return dbInstance.save(['algoliaId']);
})
.then(function(){
return res();
})
})
}
})
.then(function(){
return res();
})
})
})
})
.then(function(){
return Database.models.Topic.findAll({})
})
.then(function(topicsDB){
//If a topic is in the database, but not the topics array.
//Loop through each database entry.
Promise.each(topicsDB, function(topic){
var del = true;
//Go through topics array
for(var i=0;i<topics.length;i++){
//If a topic in the array matches a database entry, dont remove it.
if(topics[i].topic == topic.topic){
del = false;
}
}
//If no entry was found in the array for this topic in the database, remove it from the database and Algolia.
if(del){
console.log("Deleting", topic.topic, "from topic DB + Algolia", topic.algoliaId);
Search.delete('topics', [topic.algoliaId])
.then(function(){
topic.destroy();
})
}
})
})
}
是否缺少某种选项?任何帮助将不胜感激。
编辑:副本与原件之间似乎存在某种关系,但我仍然无法弄清楚是什么原因造成的。
(见谅吧)
所以这很尴尬。
我忘记了一个也在为索引做出贡献的临时服务器。
存在重复,因为您没有使用 [objectID][1] 来唯一标识您的记录。通常主键作为 objectID 可以正常工作。如果你不指定一个,Algolia 会自动分配一个,这意味着很难没有重复。
{
name: 'some name',
objectID: 'the id of the data in my database'
}
文档中有示例:https://www.algolia.com/doc/api-reference/api-methods/save-objects/#examples