Skip to content

Commit

Permalink
Merge pull request #47 from sudeeppr1998/all-1.3-dev
Browse files Browse the repository at this point in the history
content randomly gets if content is low
  • Loading branch information
sudeeppr1998 authored Oct 17, 2024
2 parents 0921654 + 0a324ca commit ecacdd5
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions src/services/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,56 @@ export class contentService {
});
}

// remove all criteria and get random content with content type
if (contentData.length <= limit) {
let randomContentQuery = {
contentSourceData: {
$elemMatch: {
},
},
contentType: contentType
};

randomContentQuery.contentSourceData.$elemMatch['language'] = language;

await this.content
.aggregate([
{
$addFields: {
contentSourceData: {
$map: {
input: '$contentSourceData',
as: 'elem',
in: {
$mergeObjects: [
'$$elem',
{
syllableCountArray: {
$objectToArray: '$$elem.syllableCountMap',
},
},
],
},
},
},
},
},
{
$match: randomContentQuery,
},
{ $sample: { size: limit - contentData.length } },
])
.exec()
.then((doc) => {
for (const docEle of doc) {
if (contentData.length == 0 || !contentDataSet.has(docEle.contentId)) {
contentDataSet.add(docEle.contentId);
contentData.push(docEle);
}
}
});
}


for (let contentDataEle of contentData) {
const regexMatchBegin = new RegExp(
Expand Down Expand Up @@ -1200,6 +1250,58 @@ export class contentService {
});
}



// remove all criteria and get random content with content type
if (contentData.length <= limit) {
let randomContentQuery = {
contentSourceData: {
$elemMatch: {
},
},
contentType: contentType
};

randomContentQuery.contentSourceData.$elemMatch['language'] = en_config.language_code;

await this.content
.aggregate([
{
$addFields: {
contentSourceData: {
$map: {
input: '$contentSourceData',
as: 'elem',
in: {
$mergeObjects: [
'$$elem',
{
syllableCountArray: {
$objectToArray: '$$elem.syllableCountMap',
},
},
],
},
},
},
},
},
{
$match: randomContentQuery,
},
{ $sample: { size: limit - contentData.length } },
])
.exec()
.then((doc) => {
for (const docEle of doc) {
if (contentData.length == 0 || !contentDataSet.has(docEle.contentId)) {
contentDataSet.add(docEle.contentId);
contentData.push(docEle);
}
}
});
}

// Remove content level
// if (contentData.length <= limit) {
// delete query.contentSourceData.$elemMatch['$and'];
Expand Down

0 comments on commit ecacdd5

Please sign in to comment.