mirror of
https://github.com/alexankitty/Myrient-Search-Engine.git
synced 2026-01-15 16:33:15 -03:00
Implemented I'm feeling lucky button
This commit is contained in:
@@ -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,
|
||||
|
||||
14
server.js
14
server.js
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user