Skip to content

Commit

Permalink
Merge pull request #261 from UoA-eResearch/rc2.6.1
Browse files Browse the repository at this point in the history
Rc2.6.1
  • Loading branch information
rosemcc authored Mar 21, 2022
2 parents 9f3905a + 2dc1d38 commit ba434d4
Show file tree
Hide file tree
Showing 62 changed files with 8,939 additions and 12,694 deletions.
19 changes: 13 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,21 @@ pipeline {
}
}
steps {
echo 'Testing research-hub-web project'
script {
echo 'Testing research-hub-web project'

// need to trim the trailing slash from the graphql server url for the e2e tests
def graphqlServer = env.SCHEMA_PATH.substring(0, env.SCHEMA_PATH.length() - 1)

dir("research-hub-web") {
echo 'Running research-hub-web unit tests'
sh 'npm run test-ci'
dir("research-hub-web") {
echo 'Running research-hub-web unit tests'
sh 'npm run test-ci'

echo 'Running research-hub-web e2e tests'
sh "npm run e2e-ci"
echo 'Running research-hub-web e2e tests'
// set the graphql server url as an env variable for Cypress
// for intercepting some of the graphql queries and returning mocked data
sh "export cypress_graphql_server=${graphqlServer} && npm run e2e-ci"
}
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions cer-graphql/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cer-graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cer-graphql",
"version": "2.5.1",
"version": "2.6.1",
"description": "A GraphQL server used to proxy and authorise requests to external data sources.",
"main": "build/index.js",
"scripts": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"@types/jest": "^27.4.0",
"@types/jsonwebtoken": "^8.5.8",
"@types/jwk-to-pem": "^2.0.0",
"aws-sdk": "^2.1058.0",
"aws-sdk": "^2.1095.0",
"aws4": "^1.10.1",
"jest": "^27.4.7",
"nodemon": "^2.0.15",
Expand Down
60 changes: 36 additions & 24 deletions hub-search-proxy/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,16 @@ module.exports.search = async (event, context) => {

let formattedQueryString = queryString;

if (queryString.split(' ').length < 5) {
// format the query string for fuzzy search if the query contains less than 5 words.
// format the query string for fuzzy search if the query contains less than 5 words.
// Also if the query string contains query operators dont make it fuzzy
if (queryString.split(' ').length < 5 && !containsOperators(queryString)) {
// modify degree of fuzziness here.
// Note: '~AUTO' is not supported currently despite what the docs say.
const fuzziness = '~2';
const fuzziness = '~2';

formattedQueryString = queryString.split(' ').map(s => {
// if word contains query operators dont make it fuzzy
formattedQueryString = queryString.split(' ').map(s => {
// if word is less than 3 letters dont make it fuzzy
const queryOperators = ['+', '|', '-', '*', '"', '(', ')'];
let matchCount = 0;
for (let i = 0; i < queryOperators.length; i++) {
if (s.indexOf(queryOperators[i]) > -1) {
matchCount++;
}
};
return (matchCount > 0 || s.length < 3) ? s : s + fuzziness;
return s.length < 3 ? s : s + fuzziness;
}).join(' ');
}

Expand Down Expand Up @@ -252,20 +245,34 @@ module.exports.search = async (event, context) => {
includes: includeInResult
},
query: {
bool: {
must: simpleQuery,
minimum_should_match: minimum_should_match,
should: queryParts,
filter: [
function_score: {
query: {
bool: {
must: simpleQuery,
minimum_should_match: minimum_should_match,
should: queryParts,
filter: [
{
term: {
"fields.searchable.en-US": true
}
},
{
terms: {
"sys.contentType.sys.id": contentTypes
}
}
]
}
},
functions: [
{
term: {
"fields.searchable.en-US": true
}
filter: {"match":{"fields.title.en-US": queryString}},
weight: 2 // boost match score for titles that contain the individual query terms
},
{
terms: {
"sys.contentType.sys.id": contentTypes
}
filter: {"match":{"fields.title.en-US.raw": queryString}},
weight: 2 // boost match score for titles that contain the exact query terms (the 'raw' field is a keyword field meaning it is not tokenised)
}
]
}
Expand Down Expand Up @@ -484,3 +491,8 @@ function formatResponse(status, body) {
}
}
}

function containsOperators(queryString) {
const queryOperators = ['+', '|', '-', '*', '"', '(', ')'];
return queryOperators.some(operator => queryString.includes(operator));
}
Loading

0 comments on commit ba434d4

Please sign in to comment.