2017-07-13 5 views
1

Ich habe ein bisschen Mühe, um Algolia richtig funktionieren zu lassen. Ich benutze NodeJS und versuche, ein wenig Synchronisation zwischen meiner Datenbank und Algolia zu haben, aber aus irgendeinem Grund scheinen eine Menge Duplikate zufällig aufzutauchen.Algolia Duplikate

enter image description here

Wie Sie mit ganz anderen Daten mit Ausnahme des Themennamen sehen kann, in einigen Fällen zwei verschiedene Einträge auftauchen. Ich führe den add-to-algolia-Code nirgendwo sonst auf, und die UUID ist deaktiviert, da Einträge, die ich einfüge, "topic-" vor ihnen haben.

function loadNewTweets(){ 
 
\t console.log("Checking..."); 
 
\t var tweets; 
 
\t var topics; 
 
\t var referenceTopics; 
 
\t Promise.all([ 
 
\t \t //stuff 
 
\t ]) 
 
\t .then(function(data){ 
 
    
 
    topics = [ 
 
     //data 
 
    ] 
 
    
 
\t \t return Promise.each(topics, function(topic, index){ 
 
\t \t \t return new Promise(function(res,rej){ 
 
\t \t \t \t Promise.all([ 
 
\t \t \t \t \t //things 
 
\t \t \t \t ]) 
 
\t \t \t \t .then(function(r){ 
 
\t \t \t \t \t var id = 'topic-'+uuid.v4(); 
 

 
\t \t \t \t \t if(!topicDB){ 
 
\t \t \t \t \t \t var obj = { 
 
\t \t \t \t \t \t \t //data 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t \t console.log("Adding", topic.topic, "to topic DB + Algolia"); 
 
\t \t \t \t \t \t return new Promise(function(res,rej){ 
 
\t \t \t \t \t \t \t var dbInstance; 
 
\t \t \t \t \t \t \t Database.models.Topic.create(obj) 
 
\t \t \t \t \t \t \t .then(function(topic){ 
 
\t \t \t \t \t \t \t \t dbInstance = topic; 
 
\t \t \t \t \t \t \t \t return Search.addData('topics', [dbInstance]) 
 
\t \t \t \t \t \t \t }) 
 
\t \t \t \t \t \t \t .then(function(content){ 
 
\t \t \t \t \t \t \t \t dbInstance.algoliaId = content.objectIDs[0]; 
 
\t \t \t \t \t \t \t \t return dbInstance.save(['algoliaId']); 
 
\t \t \t \t \t \t \t }) 
 
\t \t \t \t \t \t \t .then(function(){ 
 
\t \t \t \t \t \t \t \t return res(); 
 
\t \t \t \t \t \t \t }) 
 
\t \t \t \t \t \t }) 
 
\t \t \t \t \t } 
 
\t \t \t \t }) 
 
\t \t \t \t .then(function(){ 
 
\t \t \t \t \t return res(); 
 
\t \t \t \t }) 
 
\t \t \t }) 
 
\t \t \t 
 
\t \t }) 
 
\t }) 
 
\t .then(function(){ 
 
\t \t return Database.models.Topic.findAll({}) 
 
\t }) 
 
\t .then(function(topicsDB){ 
 
\t \t //If a topic is in the database, but not the topics array. 
 

 
\t \t //Loop through each database entry. 
 
\t \t Promise.each(topicsDB, function(topic){ 
 
\t \t \t var del = true; 
 

 
\t \t \t //Go through topics array 
 
\t \t \t for(var i=0;i<topics.length;i++){ 
 

 
\t \t \t \t //If a topic in the array matches a database entry, dont remove it. 
 
\t \t \t \t if(topics[i].topic == topic.topic){ 
 
\t \t \t \t \t del = false; 
 
\t \t \t \t } 
 
\t \t \t } 
 

 
\t \t \t //If no entry was found in the array for this topic in the database, remove it from the database and Algolia. 
 
\t \t \t if(del){ 
 
\t \t \t \t console.log("Deleting", topic.topic, "from topic DB + Algolia", topic.algoliaId); 
 
\t \t \t \t Search.delete('topics', [topic.algoliaId]) 
 
\t \t \t \t .then(function(){ 
 
\t \t \t \t \t topic.destroy(); 
 
\t \t \t \t }) 
 
\t \t \t } 
 
\t \t }) 
 
\t }) 
 
}

Gibt es irgendeine Art von Option bin ich dabei? Jede Hilfe wäre willkommen.

EDIT: Es scheint eine Art von Beziehung zwischen dem Duplikat und dem Original, aber ich kann immer noch nicht herausfinden, was es verursacht.

enter image description here

(verzeihen die Bar)

Antwort

0

Also das peinlich ist.

Ich habe einen Staging-Server vergessen, der auch zum Index beigetragen hat.

+0

Bedeutet das, dass Sie die Wurzel Ihres Problems gefunden haben? – bobylito

+0

@bobylito Ja, danke! –

5

Es gibt Duplikate, da Sie die objectID nicht verwenden, um Ihre Datensätze eindeutig zu identifizieren. Normalerweise funktioniert ein Primärschlüssel wie ein objectID. Wenn Sie keinen angeben, wird Algolia automatisch einen zuweisen, was bedeutet, dass es schwer ist, keine Duplikate zu haben.