const SimilaritySearch = require('./index'); // Create a test index with 500 strings console.log('Creating test index with 500 strings...'); const index = new SimilaritySearch(); index.addString('bio bizz'); index.addString('lightmix bizz btio substrate'); index.addString('bizz bio mix light'); console.log(`Index created with ${index.size()} strings`); // Test queries to run const queries = [ 'bio bizz', 'substrate light', 'plant growth', 'garden mix', 'random query' ]; console.log('\nRunning benchmark...'); const benchmarkResults = SimilaritySearch.benchmark(index, queries); // Display results console.log(`\nSearch results with cutoff: 0.2\n`); benchmarkResults.forEach(result => { console.log(`Query: "${result.query}"`); console.log(`Found ${result.matches} matches in ${result.timeMs.toFixed(2)} ms`); // Display top results result.topResults.forEach(match => { console.log(` ${match.similarity.toFixed(2)}: ${match.string}`); }); console.log(''); }); // Demonstrate creating a custom index console.log('Creating a custom index...'); const customIndex = new SimilaritySearch(); customIndex.addString('bio bizz'); customIndex.addString('lightmix bizz btio substrate'); customIndex.addString('bizz bio mix light'); // Add multiple strings at once customIndex.addStrings([ 'plant growth bio formula', 'garden soil substrate', 'plagron lightmix', 'Anesia Seeds Imperium X Auto 10', 'anesi' ]); console.log(`Custom index created with ${customIndex.size()} strings`); // Search with a higher similarity threshold console.log('\nSearching with higher similarity threshold (0.1) for "amnesia":'); const results = customIndex.search('amnesia haze', 0.1); results.forEach(match => { console.log(` ${match.similarity.toFixed(2)}: ${match.string}`); }); console.log('\nSearching with higher similarity threshold (0.1) for "mix light":'); const results2 = customIndex.search('mix light', 0.1); results2.forEach(match => { console.log(` ${match.similarity.toFixed(2)}: ${match.string}`); });