Skip to content

Commit 448d5ca

Browse files
committed
updated findCode method to include snippit score
1 parent 0c27cae commit 448d5ca

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

lib/controllers/files.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ exports.findCode = function(req, res, next) {
114114
// console.log('searchOptions', searchOptions);
115115

116116
File.textSearch(searchQuery, { limit: 10000 }, function(err, files){
117-
console.log('text search length: ', files.results.length);
118117
var snippIterator = function (doc, callback) {
119118
var docContent = doc.obj.contents;
120119
var repoUrl = doc.obj.repoUrl || "";
@@ -140,8 +139,7 @@ exports.findCode = function(req, res, next) {
140139
repoUrl: repoUrl,
141140
filePath: filePath,
142141
snippit: snippit,
143-
docContent: docContent,
144-
snippitRatings: snippitRatings
142+
docContent: docContent
145143
};
146144
resultsArr.push(snippitObj);
147145
});
@@ -153,14 +151,32 @@ exports.findCode = function(req, res, next) {
153151
var returnArr = [];
154152
snippitsArr = uu.flatten(snippitsArr);
155153
snippitsArr.forEach(function(snippitObj) {
156-
if ( snippitObj.snippit ) {
157-
// snippitsArr.forEach(function(snippit) {
154+
if (snippitObj.snippit) {
155+
// console.log(snippitObj.filePath);
156+
File.findOne({ filePath: snippitObj.filePath })
157+
.populate('_snippitIds')
158+
.exec(function(err, file) {
159+
if (err) console.log(err);
160+
// console.log(typeof file._snippitIds, ': ', file._snippitIds);
161+
if (file._snippitIds.length > 0) {
162+
for (var i = 0; i < file._snippitIds.length; i++){
163+
if (snippitObj.snippit === file._snippitIds[i].snippit) {
164+
snippitObj.snippitScore = file._snippitIds[i].score;
165+
}
166+
}
167+
}
168+
if (!snippitObj.snippitScore) {
169+
snippitObj.snippitScore = 0;
170+
}
158171
returnArr.push(snippitObj);
159-
// });
172+
});
160173
}
161174
});
162175

163-
res.json({ snippits: returnArr });
176+
// timeout just temporary --> will fix async issue in next commit
177+
setTimeout(function(){
178+
res.json({ snippits: returnArr });
179+
}, 5000);
164180
});
165181

166182

0 commit comments

Comments
 (0)