update: move todos into their resp. file
This commit is contained in:
@@ -8,9 +8,4 @@ to run just run
|
|||||||
|
|
||||||
```
|
```
|
||||||
make run
|
make run
|
||||||
```
|
```
|
||||||
|
|
||||||
### TODO
|
|
||||||
|
|
||||||
+ unit tests for business logic
|
|
||||||
+ export in JSON
|
|
||||||
+16
-11
@@ -1,5 +1,15 @@
|
|||||||
|
// TODO: unit tests for business logic
|
||||||
|
// TODO: export in JSON
|
||||||
|
|
||||||
const cheerio = require("cheerio");
|
const cheerio = require("cheerio");
|
||||||
|
|
||||||
|
function filterJson(data) {
|
||||||
|
var filtereddata = [];
|
||||||
|
data.forEach(element => {
|
||||||
|
filtereddata.push();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSearch(req, res) {
|
async function handleSearch(req, res) {
|
||||||
try {
|
try {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
@@ -8,16 +18,11 @@ async function handleSearch(req, res) {
|
|||||||
return res.status(400).send("Missing search query");
|
return res.status(400).send("Missing search query");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here we use a searx.ng instance (a meta-search engine) and filter out google search results.
|
/* Here we use a local searx.ng instance (a meta-search engine) and filter out google/startpage
|
||||||
* by testing, i've found out that !goc (google's programmable search engine) is more reliable for
|
* search results. By testing, i've found out that !sp (startpage) ro !goc (google's programmable
|
||||||
* this kind of operation.
|
* search engine) is more reliable for this kind of operation that regular google.
|
||||||
* the instance could be changed if the current one e.g. goes out of service.
|
* A local instance instead of an already available one is used because of bot detection. :)
|
||||||
*/
|
*/
|
||||||
/**
|
|
||||||
* more instances:
|
|
||||||
* https://baresearch.org/
|
|
||||||
*/
|
|
||||||
//const url = `https://baresearch.org/search?q=!goc+${encodeURIComponent(query)}`;
|
|
||||||
const searxngUrl = process.env.SEARXNG_URL || "http://localhost:8080";
|
const searxngUrl = process.env.SEARXNG_URL || "http://localhost:8080";
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
q: query,
|
q: query,
|
||||||
@@ -35,10 +40,10 @@ async function handleSearch(req, res) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
res.json(data.results || []);
|
res.json(filterJson(data.results || []));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[SEARCH.JS] " + error);
|
console.error("[SEARCH.JS] " + error);
|
||||||
res.status(500).send("Search failed");
|
res.status(500).send("<p><b>Search failed!<br>See the console for the error.</b></p>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user