Implemented I'm feeling lucky button

This commit is contained in:
Alexandra
2024-10-17 02:10:44 -06:00
parent a19a80aea6
commit 63e6bd5462
3 changed files with 17 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ export default class Searcher{
createIndex(fileArr){
this.miniSearch = new MiniSearch({
fields: ['name', 'category', 'type'],
storeFields: ['filename', 'category', 'type', 'date', 'size', 'region'],
storeFields: ['filename', 'category', 'type', 'date', 'size', 'region', 'path'],
searchOptions: {
boost: { name: 2 },
fuzzy: this.distance,

View File

@@ -12,7 +12,6 @@ var fileListPath = './filelist.json'
var categoryListPath = './lib/categories.json'
var categoryList = await parseJsonFile(categoryListPath)
var crawlTime = await fileTime(fileListPath)
console.log(crawlTime)
var fileList = []
@@ -61,6 +60,19 @@ app.get('/search', function(req, res) {
})
})
app.get("/lucky", function(req, res) {
let results = search.findAllMatches(req.query.q)
if(process.env.DEBUG == "1"){
console.log(results)
}
if(results.items.length){
res.redirect(results.items[0].path)
}
else{
res.redirect("/")
}
})
server.listen(process.env.PORT, process.env.BIND_ADDRESS)
server.on('listening', function() {
console.log('Server started on %s:%s.', server.address().address, server.address().port)

View File

@@ -10,11 +10,11 @@ _ / / / _ /_/ /_ / _ / / __/ / / / /_
Search!
</pre>
<div class="text-center text-white">
<form action="/search">
<form>
<input type="text" style="width: 80%;display: inline;" class="form-control bg-dark text-white mb-2" name="q">
<div>
<button type="submit" class="btn btn-secondary">Myrient Search</button>
<button class="btn btn-secondary">I'm Feeling Lucky</button>
<button type="submit" formaction="/search" class="btn btn-secondary">Myrient Search</button>
<button type="submit" formaction="/lucky" class="btn btn-secondary">I'm Feeling Lucky</button>
</div>
</form>
</div>