Skip to content

Commit ea58495

Browse files
committed
Merge branch 'feat/merge-search-results'
2 parents 375b315 + 4f1caf1 commit ea58495

File tree

50 files changed

+6521
-5067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6521
-5067
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Chrome",
6+
"request": "launch",
7+
"type": "pwa-chrome",
8+
"url": "http://localhost:4200",
9+
"webRoot": "${workspaceFolder}"
10+
},
11+
12+
{
13+
"type": "node",
14+
"request": "launch",
15+
"name": "Node: Nodemon",
16+
"runtimeExecutable": "npm",
17+
"runtimeArgs": ["start"],
18+
"outputCapture": "std",
19+
},
20+
]
21+
}

backend/package-lock.json

Lines changed: 2152 additions & 2131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88
"integration-tests": "NODE_ENV=test nyc mocha '**/*.spec.js' --exit"
99
},
1010
"dependencies": {
11-
"aws-sdk": "^2.640.0",
12-
"body-parser": "^1.18.3",
13-
"cheerio": "latest",
14-
"cookie-parser": "~1.4.3",
15-
"debug": "^4.1.0",
11+
"aws-sdk": "^2.1048.0",
12+
"body-parser": "^1.19.1",
13+
"cheerio": "^1.0.0-rc.10",
14+
"cookie-parser": "^1.4.6",
15+
"debug": "^4.3.3",
1616
"escape-string-regexp": "^1.0.5",
17-
"express": "^4.16.4",
17+
"express": "^4.17.2",
1818
"express-async-errors": "^3.1.1",
1919
"fs-extra": "^7.0.1",
20-
"helmet": "^3.22.0",
21-
"http-status-codes": "^1.3.0",
20+
"helmet": "^3.23.3",
21+
"http-status-codes": "^1.4.0",
2222
"keycloak-connect": "6.0.1",
23-
"mongoose": "^5.12.3",
24-
"morgan": "^1.9.1",
25-
"multer": "^1.4.2",
26-
"multer-s3": "^2.9.0",
23+
"mongoose": "^5.13.14",
24+
"morgan": "^1.10.0",
25+
"multer": "^1.4.4",
26+
"multer-s3": "^2.10.0",
2727
"node-cache": "^5.1.2",
2828
"request": "latest",
29-
"rotating-file-stream": "^1.3.2",
29+
"rotating-file-stream": "^1.4.6",
3030
"serve-favicon": "^2.5.0",
3131
"showdown": "^1.9.1",
3232
"superagent": "^4.1.0",
33-
"swagger-ui-express": "^4.0.2",
33+
"swagger-ui-express": "^4.3.0",
3434
"yamljs": "^0.3.0"
3535
},
3636
"devDependencies": {
37-
"chai": "^4.2.0",
37+
"chai": "^4.3.4",
3838
"chai-as-promised": "^7.1.1",
39-
"eslint": "^6.6.0",
39+
"eslint": "^8.5.0",
4040
"jsonwebtoken": "^8.5.1",
41-
"mocha": "^7.2.0",
42-
"nodemon": "^2.0.2",
43-
"nyc": "^15.0.0",
44-
"supertest": "^3.4.1"
41+
"mocha": "^9.1.3",
42+
"nodemon": "^2.0.15",
43+
"nyc": "^15.1.0",
44+
"supertest": "^3.4.2"
4545
}
4646
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* ****** Bookmarks ****** */
2+
// delete old index
3+
db.bookmarks.dropIndex("full_text_search");
4+
5+
//recreate index
6+
db.bookmarks.createIndex(
7+
{
8+
name: "text",
9+
location: "text",
10+
description: "text",
11+
tags: "text",
12+
sourceCodeURL: "text",
13+
},
14+
{
15+
weights: {
16+
name: 13,
17+
location: 8,
18+
description: 5,
19+
tags: 21,
20+
sourceCodeURL: 3
21+
},
22+
name: "full_text_search",
23+
default_language: "none",
24+
language_override: "none"
25+
}
26+
);
27+
28+
/* ****** Snippets ****** */
29+
// delete old index
30+
db.snippets.dropIndex("full_text_search");
31+
32+
//recreate
33+
34+

backend/src/model/snippet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CodeSnippetSchema = new Schema({
99
code: String,
1010
language: String,
1111
comment: String,
12+
commentAfter: String,
1213
});
1314

1415
const snippetSchema = new Schema({

backend/src/routes/users/bookmarks/personal-bookmarks-search.service.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Bookmark = require('../../../model/bookmark');
22
const bookmarksSearchHelper = require('../../../common/bookmarks-search.helper');
33

4-
let findPersonalBookmarks = async function (query, page, limit, userId, searchInclude) {
4+
let findPersonalBookmarks = async function (userId, query, page, limit, searchInclude) {
55
//split in text and tags
66
const searchedTermsAndTags = bookmarksSearchHelper.splitSearchQuery(query);
77
let searchedTerms = searchedTermsAndTags.terms;
@@ -11,17 +11,17 @@ let findPersonalBookmarks = async function (query, page, limit, userId, searchIn
1111
const {specialSearchFilters, nonSpecialSearchTerms} = bookmarksSearchHelper.extractSpecialSearchTerms(searchedTerms);
1212

1313
if ( searchedTerms.length > 0 && searchedTags.length > 0 ) {
14-
bookmarks = await getPersonalBookmarksForTagsAndTerms(searchedTags, nonSpecialSearchTerms, page, limit, userId, specialSearchFilters, searchInclude);
14+
bookmarks = await getPersonalBookmarksForTagsAndTerms( userId, searchedTags, nonSpecialSearchTerms, page, limit, specialSearchFilters, searchInclude);
1515
} else if ( searchedTerms.length > 0 ) {
16-
bookmarks = await getPersonalBookmarksForSearchedTerms(nonSpecialSearchTerms, page, limit, userId, specialSearchFilters, searchInclude);
16+
bookmarks = await getPersonalBookmarksForSearchedTerms(userId, nonSpecialSearchTerms, page, limit, specialSearchFilters, searchInclude);
1717
} else {
18-
bookmarks = await getPersonalBookmarksForSearchedTags(searchedTags, page, limit, userId, specialSearchFilters);
18+
bookmarks = await getPersonalBookmarksForSearchedTags(userId, searchedTags, page, limit, specialSearchFilters);
1919
}
2020

2121
return bookmarks;
2222
}
2323

24-
let getPersonalBookmarksForTagsAndTerms = async function (searchedTags, nonSpecialSearchTerms, page, limit, userId, specialSearchFilters, searchInclude) {
24+
let getPersonalBookmarksForTagsAndTerms = async function (userId, searchedTags, nonSpecialSearchTerms, page, limit, specialSearchFilters, searchInclude) {
2525
let filter = {
2626
userId: userId,
2727
tags:
@@ -56,7 +56,7 @@ let getPersonalBookmarksForTagsAndTerms = async function (searchedTags, nonSpeci
5656
}
5757

5858

59-
let getPersonalBookmarksForSearchedTerms = async function (nonSpecialSearchTerms, page, limit, userId, specialSearchFilters, searchInclude) {
59+
let getPersonalBookmarksForSearchedTerms = async function ( userId, nonSpecialSearchTerms, page, limit,specialSearchFilters, searchInclude) {
6060

6161
let filter = {userId: userId };
6262
if ( nonSpecialSearchTerms.length > 0 ) {
@@ -84,7 +84,7 @@ let getPersonalBookmarksForSearchedTerms = async function (nonSpecialSearchTerms
8484
}
8585

8686

87-
let getPersonalBookmarksForSearchedTags = async function (searchedTags, page, limit, userId, specialSearchFilters) {
87+
let getPersonalBookmarksForSearchedTags = async function (userId, searchedTags, page, limit, specialSearchFilters) {
8888
let filter = {
8989
userId: userId,
9090
tags:

backend/src/routes/users/bookmarks/personal-bookmarks.router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ personalBookmarksRouter.get('/', keycloak.protect(), async (request, response, n
4747
const {page, limit} = PaginationQueryParamsHelper.getPageAndLimit(request);
4848
const searchInclude = request.query.include;
4949
if ( searchText ) {
50-
const bookmarks = await personalBookmarksSearchService.findPersonalBookmarks(searchText, page, limit, request.params.userId, searchInclude);
50+
const bookmarks = await personalBookmarksSearchService.findPersonalBookmarks(request.params.userId, searchText, page, limit, searchInclude);
5151
return response.send(bookmarks);
5252
} else {
5353
next();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const personalBookmarksSearchService = require('./bookmarks/personal-bookmarks-search.service');
2+
const personalSnippetsSearchService = require('../../common/snippets-search.service');
3+
4+
let getPersonalSearchResults = async function (userId, query, page, limit, searchInclude) {
5+
6+
const foundBookmarks = await personalBookmarksSearchService.findPersonalBookmarks(userId, query, page, limit, searchInclude);
7+
const foundSnippets = await personalSnippetsSearchService.findSnippets(userId, query, page, limit, searchInclude);
8+
9+
return mergeResultsByScore(foundBookmarks, foundSnippets);
10+
}
11+
12+
function mergeResultsByScore(arr1, arr2) {
13+
let i = 0;
14+
let j = 0;
15+
let result = [];
16+
while (i < arr1.length && j < arr2.length) {
17+
if ( arr1[i].score >= arr2[j].score ) {
18+
result.push(arr1[i]);
19+
i++;
20+
} else {
21+
result.push(arr2[j]);
22+
j++;
23+
}
24+
}
25+
while (i < arr1.length) {
26+
result.push(arr1[i]);
27+
i++;
28+
}
29+
while (j < arr2.length) {
30+
result.push(arr2[j]);
31+
j++;
32+
}
33+
return result;
34+
}
35+
36+
module.exports = {
37+
getPersonalSearchResults: getPersonalSearchResults
38+
};

backend/src/routes/users/snippets/personal-snippets.router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ personalSnippetsRouter.put('/:snippetId', keycloak.protect(), async (request, re
120120

121121
UserIdValidator.validateUserId(request);
122122

123-
const codeletData = request.body;
123+
const snippetData = request.body;
124124

125125
const {userId, snippetId} = request.params;
126-
const updatedBookmark = await PersonalSnippetsService.updateSnippet(userId, snippetId, codeletData);
126+
const updatedSnippet = await PersonalSnippetsService.updateSnippet(userId, snippetId, snippetData);
127127

128-
return response.status(HttpStatus.OK).send(updatedBookmark);
128+
return response.status(HttpStatus.OK).send(updatedSnippet);
129129
});
130130

131131
/*

backend/src/routes/users/snippets/personal-snippets.service.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const Snippet = require('../../../model/snippet');
22

33
const NotFoundError = require('../../../error/not-found.error');
44

5-
const CodeletInputValidator = require('./snippet-input.validator');
5+
const SnippetInputValidator = require('./snippet-input.validator');
66

77
/**
88
* CREATE snippet for user
99
*/
1010
let createSnippet = async function (userId, snippetData) {
11-
CodeletInputValidator.validateSnippetInput(userId, snippetData);
11+
SnippetInputValidator.validateSnippetInput(userId, snippetData);
1212

1313
const snippet = new Snippet(snippetData);
1414
let newSnippet = await snippet.save();
@@ -52,24 +52,24 @@ let getAllMySnippets = async (userId) => {
5252
* full UPDATE via PUT - that is the whole document is required and will be updated
5353
* the descriptionHtml parameter is only set in backend, if only does not come front-end (might be an API call)
5454
*/
55-
let updateSnippet = async (userId, codeletId, codeletData) => {
55+
let updateSnippet = async (userId, codeletId, snippetData) => {
5656

57-
CodeletInputValidator.validateSnippetInput(userId, codeletData);
57+
SnippetInputValidator.validateSnippetInput(userId, snippetData);
5858

59-
const updatedCodelet = await Snippet.findOneAndUpdate(
59+
const updatedSnippet = await Snippet.findOneAndUpdate(
6060
{
6161
_id: codeletId,
6262
userId: userId
6363
},
64-
codeletData,
64+
snippetData,
6565
{new: true}
6666
);
6767

68-
const codeletNotFound = !updatedCodelet;
69-
if ( codeletNotFound ) {
70-
throw new NotFoundError('Snippet NOT_FOUND with id: ' + codeletId + ' AND title: ' + codeletData.title);
68+
const snippetNotFound = !updatedSnippet;
69+
if ( snippetNotFound ) {
70+
throw new NotFoundError('Snippet NOT_FOUND with id: ' + codeletId + ' AND title: ' + snippetData.title);
7171
} else {
72-
return updatedCodelet;
72+
return updatedSnippet;
7373
}
7474
};
7575

0 commit comments

Comments
 (0)