From 762d85c95690f510bec4dd8c37c05454ae1be4fc Mon Sep 17 00:00:00 2001 From: Geo Halkiadakis Date: Thu, 11 Apr 2024 19:16:31 +0300 Subject: introduce resemblance; compare match implementations; retro-search in progress --- benchmark/match-str.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 benchmark/match-str.js (limited to 'benchmark/match-str.js') diff --git a/benchmark/match-str.js b/benchmark/match-str.js new file mode 100644 index 0000000..7760b4e --- /dev/null +++ b/benchmark/match-str.js @@ -0,0 +1,46 @@ +const products = require('../data/products.json'); +const match = require('../pieces/match-util.js'); +var microtime = require('microtime'); + + +query = 'solokata'; + +function run() { + + var f0 = microtime.nowDouble(); + // for(let i = 0 ; i < 100 ; i++) + let result = matchQuery(query); + var f1 = microtime.nowDouble(); + + return { + t: f1-f0, + q: query, + result: result + } +} + + +function matchQuery(q) { + var result = []; + + for(let i = 0; i < products.length; i++) { + let found = false; + let similarity = 0; + products[i].kb.split(' ').forEach( w => { + let sim = match.resemblance(q, w, 2); + if (sim > 0.5) { + found = true; + similarity = (sim > similarity) ? sim : similarity; + } + }); + if (found) { + products[i].similarity = similarity; + result.push(products[i]); + } + } + + return result +} + + +module.exports = { run } \ No newline at end of file -- cgit v1.2.3