Skip to content

Commit e1e747b

Browse files
committed
vertailu-skriptin päivitys
1 parent 634312a commit e1e747b

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

backend/scripts/compareSearch.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env node
22
/*
33
Compare search results between two Finlex services.
4-
Usage:
5-
node scripts/compareSearch.js --q tupakka --language fin
6-
node scripts/compareSearch.js --q tupakka --language fin --prod https://... --staging https://...
7-
node scripts/compareSearch.js --file words.txt --language fin
4+
Usage (run from repo root):
5+
node backend/scripts/compareSearch.js --q tupakka --language fin
6+
node backend/scripts/compareSearch.js --q tupakka --language fin --app1 http://... --app2 http://...
7+
node backend/scripts/compareSearch.js --file backend/scripts/queries.txt --language fin
88
*/
99

1010
import axios from 'axios';
1111
import { readFileSync } from 'fs';
1212

1313
function parseArgs() {
1414
const args = process.argv.slice(2);
15-
const out = { q: null, file: null, language: 'fin', prod: 'https://finlex.ext.ocp-prod-0.k8s.it.helsinki.fi', staging: 'https://finlex-lukija-ohtuprojekti-staging.ext.ocp-prod-0.k8s.it.helsinki.fi' };
15+
const out = { q: null, file: null, language: 'fin', app1: 'https://finlex-lukija-ohtuprojekti-staging.ext.ocp-prod-0.k8s.it.helsinki.fi', app2: 'https://finlex-lukija2-ohtuprojekti-staging.ext.ocp-prod-0.k8s.it.helsinki.fi' };
1616
for (let i = 0; i < args.length; i++) {
1717
const a = args[i];
1818
if (a === '--q') out.q = args[++i];
1919
else if (a === '--file') out.file = args[++i];
2020
else if (a === '--language') out.language = args[++i];
21-
else if (a === '--prod') out.prod = args[++i];
22-
else if (a === '--staging') out.staging = args[++i];
21+
else if (a === '--app1') out.app1 = args[++i];
22+
else if (a === '--app2') out.app2 = args[++i];
2323
}
2424
if (!out.q && !out.file) {
2525
console.error('Missing --q query parameter or --file path');
@@ -65,28 +65,28 @@ function diffLists(aList, bList) {
6565
return { onlyA, onlyB };
6666
}
6767

68-
async function compareQuery(q, language, prod, staging) {
69-
const prodUrl = buildUrl(prod, q, language);
70-
const stagingUrl = buildUrl(staging, q, language);
68+
async function compareQuery(q, language, app1, app2) {
69+
const app1Url = buildUrl(app1, q, language);
70+
const app2Url = buildUrl(app2, q, language);
7171

7272
try {
73-
const [prodResp, stagingResp] = await Promise.all([
74-
axios.get(prodUrl, { headers: { Accept: 'application/json' } }),
75-
axios.get(stagingUrl, { headers: { Accept: 'application/json' } }),
73+
const [app1Resp, app2Resp] = await Promise.all([
74+
axios.get(app1Url, { headers: { Accept: 'application/json' } }),
75+
axios.get(app2Url, { headers: { Accept: 'application/json' } }),
7676
]);
7777

78-
const prodList = asArray(prodResp.data);
79-
const stagingList = asArray(stagingResp.data);
78+
const app1List = asArray(app1Resp.data);
79+
const app2List = asArray(app2Resp.data);
8080

81-
const { onlyA: onlyProd, onlyB: onlyStaging } = diffLists(prodList, stagingList);
81+
const { onlyA: onlyApp1, onlyB: onlyApp2 } = diffLists(app1List, app2List);
8282

8383
return {
8484
q,
85-
prodCount: prodList.length,
86-
stagingCount: stagingList.length,
87-
onlyProd,
88-
onlyStaging,
89-
match: onlyProd.length === 0 && onlyStaging.length === 0
85+
app1Count: app1List.length,
86+
app2Count: app2List.length,
87+
onlyApp1,
88+
onlyApp2,
89+
match: onlyApp1.length === 0 && onlyApp2.length === 0
9090
};
9191
} catch (err) {
9292
return {
@@ -97,7 +97,7 @@ async function compareQuery(q, language, prod, staging) {
9797
}
9898

9999
async function main() {
100-
const { q, file, language, prod, staging } = parseArgs();
100+
const { q, file, language, app1, app2 } = parseArgs();
101101

102102
let queries = [];
103103
if (file) {
@@ -107,20 +107,20 @@ async function main() {
107107
queries = [q];
108108
}
109109

110-
console.log(`Testing ${queries.length} queries against prod and staging (language=${language})\n`);
110+
console.log(`Testing ${queries.length} queries against app1 and app2 (language=${language})\n`);
111111

112112
const results = [];
113113
for (const query of queries) {
114114
process.stdout.write(`Testing "${query}"... `);
115-
const result = await compareQuery(query, language, prod, staging);
115+
const result = await compareQuery(query, language, app1, app2);
116116
results.push(result);
117117

118118
if (result.error) {
119119
console.log(`ERROR: ${result.error}`);
120120
} else if (result.match) {
121-
console.log(`✓ Match (prod: ${result.prodCount}, staging: ${result.stagingCount})`);
121+
console.log(`✓ Match (app1: ${result.app1Count}, app2: ${result.app2Count})`);
122122
} else {
123-
console.log(`✗ Diff (prod: ${result.prodCount}, staging: ${result.stagingCount}, only-prod: ${result.onlyProd.length}, only-staging: ${result.onlyStaging.length})`);
123+
console.log(`✗ Diff (app1: ${result.app1Count}, app2: ${result.app2Count}, only-app1: ${result.onlyApp1.length}, only-app2: ${result.onlyApp2.length})`);
124124
}
125125
}
126126

@@ -137,12 +137,12 @@ async function main() {
137137
if (result.error) {
138138
console.log(`\n"${result.q}": ERROR - ${result.error}`);
139139
} else {
140-
console.log(`\n"${result.q}": prod=${result.prodCount}, staging=${result.stagingCount}`);
141-
if (result.onlyProd.length > 0) {
142-
console.log(` Only in prod (${result.onlyProd.length}):`, result.onlyProd.map(i => `${i.docYear}/${i.docNumber}`).join(', '));
140+
console.log(`\n"${result.q}": app1=${result.app1Count}, app2=${result.app2Count}`);
141+
if (result.onlyApp1.length > 0) {
142+
console.log(` Only in app1 (${result.onlyApp1.length}):`, result.onlyApp1.map(i => `${i.docYear}/${i.docNumber}`).join(', '));
143143
}
144-
if (result.onlyStaging.length > 0) {
145-
console.log(` Only in staging (${result.onlyStaging.length}):`, result.onlyStaging.map(i => `${i.docYear}/${i.docNumber}`).join(', '));
144+
if (result.onlyApp2.length > 0) {
145+
console.log(` Only in app2 (${result.onlyApp2.length}):`, result.onlyApp2.map(i => `${i.docYear}/${i.docNumber}`).join(', '));
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)