genesis
This commit is contained in:
53
test.js
Normal file
53
test.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const SimilaritySearch = require('./index');
|
||||
|
||||
// Create a test index with 500 strings
|
||||
console.log('Creating test index with 500 strings...');
|
||||
const index = SimilaritySearch.createTestIndex(500);
|
||||
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'
|
||||
]);
|
||||
|
||||
console.log(`Custom index created with ${customIndex.size()} strings`);
|
||||
|
||||
// Search with a higher similarity threshold
|
||||
console.log('\nSearching with higher similarity threshold (0.3):');
|
||||
const results = customIndex.search('bio bizz', 0.3);
|
||||
results.forEach(match => {
|
||||
console.log(` ${match.similarity.toFixed(2)}: ${match.string}`);
|
||||
});
|
||||
Reference in New Issue
Block a user