Skip to content

Commit 9c85c4b

Browse files
committed
Updated Search function to support Fuzzy Search (commented out previous search function for now)
1 parent cdfa9ad commit 9c85c4b

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
2-
32
import { Command } from 'commander';
43
import readline from 'readline';
54
import fs, { read } from 'fs';
65
import path, { resolve } from 'path';
76
import clipboardy from 'clipboardy';
87
import { json } from 'stream/consumers';
8+
import Fuse from 'fuse.js';
99
// const {PrismaClient}=require(`@prisma/client`);
1010
const DATA_FILE=path.resolve('./snippet.json');
1111

@@ -223,7 +223,33 @@ program
223223
})
224224
});
225225

226-
// search snippet
226+
// search snippet (OLDER)
227+
// program
228+
// .command('search-snippet')
229+
// .description('search for the snippet you are looking for on the basis of language,keywords and tags')
230+
// .option('-l,--lang<language>','Filter on the basis of programming language')
231+
// .option('-k,--key<keyword>','Filter on the basis of keywords used')
232+
// .option(`--tags <tags>`, `New comma-separated tags`, val => val.split(`,`))
233+
234+
// .action((options)=>{
235+
// const snippets=loadSnippets();
236+
// const matches=snippets.filter(snippet=>{
237+
// const matchlang =options.lang? options.lang===snippet.lang:true;
238+
// const matchtag =options.tag?snippet.tag?.includes(options.tag):true;
239+
// const matchkey=options.keywords?fs.readFileSync(path.resolve(filePath),'utf-8').includes(options.keywords):true;
240+
241+
// return matchlang && matchtag && matchkey;
242+
// });
243+
// if(!matches.length) return console.log("Snippet not found");
244+
// matches.forEach((s,i)=>{
245+
// console.log(`\n ${i+1}. ${s.name}[${s.lang}]`);
246+
// console.log(`Tags: ${snippets.tags?.join(', ')}`);
247+
// console.log(`File: ${s.file}`);
248+
// console.log('-----------------------------');
249+
// })
250+
// })
251+
252+
//Search snippet FUZZY
227253
program
228254
.command('search-snippet')
229255
.description('search for the snippet you are looking for on the basis of language,keywords and tags')

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"clipboard": "^2.0.11",
1818
"clipboardy": "^4.0.0",
19-
"commander": "^14.0.0"
19+
"commander": "^14.0.0",
20+
"fuse.js": "^7.1.0"
2021
}
2122
}

0 commit comments

Comments
 (0)