2017-07-13 9 views
1

Algoliaを正しく動作させるのに少し問題があります。私はNodeJSを使用していて、データベースとAlgoliaの間で少しの同期をとろうとしていますが、何らかの理由で重複して大量にポップアップするようです。Algolia Duplicates

enter image description here

あなたが見ることができるように、いくつかのケースでは二つの異なるエントリはトピック名を除いて完全に異なるデータをポップアップされています。私は他にどこでも追加 - アルゴリアコードを実行していません、そして、UUIDは私が入れたエントリーがそれらの前に "topic-"を持っているので、オフです。

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 }) 
 
}

私が欠けているオプションのいくつかの並べ替えはありますか?どんな助けもありがとう。

EDIT:複製とオリジナルとの間に何らかの関係があるようですが、それでも何が原因であるのか把握できません。

enter image description here

(バーを許す)

答えて

0

だから、これは恥ずかしいです。

インデックスにも寄与していたステージングサーバーを忘れていました。

+0

これは、問題の根本を見つけたことを意味しますか? – bobylito

+0

@bobylitoはい、ありがとう! –

5

レコードを一意に識別するためにobjectIDを使用していないため、重複があります。通常、プライマリキーはobjectIDとして正常に動作します。あなたが指定しない場合、Algoliaは自動的に1つを割り当てます。つまり、重複しないことは難しいでしょう。