Search by tags ( multible tags supported )

/search?tag=tag1+tag2+etc // for searching
/search?api // for api searching uses all other args
/search?sort=sortingmethod // not implemented yet ( future supported "hot" / "new" / "rit"
/search?pi // sends postdata instead of just postids
master
derzombiiie 2021-08-22 01:13:01 +02:00
parent 3b9a0ed447
commit 601a161099
12 changed files with 411 additions and 26 deletions

View File

@ -1 +1 @@
passhash: tKi4GQ+TZyOM1qSzTYfd+1CQg5zutKPhLNKV6IufPM0=
passhash: jGl25bVBBBW96Qi9Te4V37Fnqchz/Eu4qB9vKrRIqRg=

View File

@ -38,7 +38,7 @@ class entry {
element.innerHTML +=
`<div class="entry">
<a class="title" href="/posts?post=${this.id}">${this.title}</a>
<div class="author">BY <a class="author" href="/search?author=${this.author}">${this.author}</a></div>
<div class="subtitle author">BY <a class="author" href="/search?author=${this.author}">${this.author}</a></div>
<hr class="seperator">
<div class="preview">${this.desc}</div>
<hr class="seperator">

16
html/js/search.js Normal file
View File

@ -0,0 +1,16 @@
$(document).ready(() => {
results = []
for ( let i = 0 ; i < searchDATA.length ; i++ ) {
// generate shorted description:
let desc = ""
let d = searchDATA[i].desc.split(" ")
for( let i = 0 ; i < 10 ; i ++ ) {
desc += d[i] + " "
}
desc += "..."
results.push( new entry( searchDATA[i].title, searchDATA[i].author, desc, "", searchDATA[i].tags, searchDATA[i].id, searchDATA[i].rating ) )
results[results.length-1].appendto(".content")
console.log("loop")
}
})

40
html/search/index.html Normal file
View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>derzombiiie.com - home</title>
<link rel="stylesheet" href="/static/style/fonts.css">
<link rel="stylesheet" href="/static/style/main.css">
<script src="/static/js/jq.js"></script>
<script src="/config.js"></script>
<script>
const searchDATA = ""//<!--SEARCH-DATA-INJECT-->//
</script>
<script src="/static/js/themes.js"></script>
<script src="/static/js/menubar.js"></script>
<script src="/static/js/footer.js"></script>
<script src="/static/js/entry.js"></script>
<script src="/static/js/share.js"></script>
<script src="/static/js/search.js"></script>
</head>
<body>
<div class="menubox"></div>
<div class="content">
<div class="entrybox">
<div class="entry metaentry">
<div class="title">search</div>
<div class="subtitle search">placeholder for search params</div>
</div>
</div>
</div>
</div>
<div class="footer"></div>
</body>
</html>

View File

@ -55,7 +55,7 @@ body, html {
.entrybox > .metaentry > .title:hover {
text-decoration: none;
}
.entrybox > .entry > .author {
.entrybox > .entry > .subtitle {
font-style: italic;
font-family: slkscr;
font-size: 1em;

View File

@ -50,7 +50,7 @@
.entrybox > .metaentry > .title:hover {
text-decoration: none;
}
.entrybox > .entry > .author {
.entrybox > .entry > .subtitle {
font-style: italic;
font-family: slkscr;
font-size: 1em;
@ -217,4 +217,3 @@
display: flex;
justify-content: left;
}

View File

@ -108,7 +108,6 @@ textarea.comment {
width: calc( 100% - 0.5em);
height: 5em;
}
.comments > .comment {
position: relative;
width: calc( 100% - 4em );
@ -118,10 +117,11 @@ textarea.comment {
padding-right: 0.5em;
margin-bottom: 1em;
}
.comments > .comment > .author {
.comments > .comment > .subtitle {
position: relative;
left: 0px;
}
.comments > .comment > .seperator {
position: relative;
top: 0.2em;
@ -210,4 +210,3 @@ textarea.comment {
top: 0.1em;
left: 0.1em;
}

View File

@ -1409,3 +1409,194 @@ err, crashed!"
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629306246326 | Dumping config:
1629306246333 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629306252094 | Reading posts sorted by "new" with a length of 10
1629373879812 | Reading posts sorted by "new" with a length of 10
1629373889829 | Reading post 0
1629373890195 | Reading comments from post "0", with length: undefined
1629373891354 | Trying to vote on post: 0; and vote: +; iptkn: 2383825147775950; ip: 94.134.179.144;
1629373892779 | Trying to vote on post: 0; and vote: -; iptkn: 2054701222640405; ip: 94.134.179.144;
1629373893432 | Trying to vote on post: 0; and vote: +; iptkn: 4439234544853926; ip: 94.134.179.144;
1629373894017 | Trying to vote on post: 0; and vote: +; iptkn: 5619401935745137; ip: 94.134.179.144;
1629373897038 | Reading post 0
1629373917421 | Trying to vote on post: 0; and vote: -; iptkn: 4134206592697756; ip: 94.134.179.144;
1629373943402 | Reading comments from post "0", with length: undefined
1629373943454 | Trying to comment to post "0", from ip "94.134.179.144" (tkn: 8449268963154284) with content: "fgaW "
--- SEPERATOR ---
--- SEPERATOR ---
1629472893008 | Dumping config:
1629472893014 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629472906193 | Reading posts sorted by "new" with a length of 10
1629474001767 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
1629475097464 | Dumping config:
1629475097470 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629475138252 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
1629475158832 | Dumping config:
1629475158846 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629475224268 | Reading post 0
1629475224908 | Reading comments from post "0", with length: undefined
1629475226966 | Trying to vote on post: 0; and vote: +; iptkn: 8157706522672703; ip: 87.123.198.188;
1629477544653 | Reading post 0
1629477545200 | Reading comments from post "0", with length: undefined
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629478842932 | Dumping config:
1629478842937 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629478844300 | Reading posts sorted by "new" with a length of 10
1629478849346 | Reading post 0
1629478849884 | Reading comments from post "0", with length: undefined
1629478852676 | Reading post 1
--- SEPERATOR ---
--- SEPERATOR ---
1629479415775 | Dumping config:
1629479415781 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629479438454 | Reading posts sorted by "new" with a length of 10
1629479440140 | Reading posts sorted by "new" with a length of 10
1629479441307 | Reading posts sorted by "new" with a length of 10
1629479445001 | Reading posts sorted by "new" with a length of 10
1629479446892 | Reading posts sorted by "new" with a length of 10
1629479449146 | Reading posts sorted by "new" with a length of 10
1629479451290 | Reading posts sorted by "new" with a length of 10
1629479454618 | Reading post 1
1629479456232 | Reading post 1
1629479457937 | Reading posts sorted by "new" with a length of 10
1629479459127 | Reading posts sorted by "new" with a length of 10
1629479460135 | Reading posts sorted by "new" with a length of 10
1629479461156 | Reading posts sorted by "new" with a length of 10
1629479461988 | Reading posts sorted by "new" with a length of 10
1629479462904 | Reading posts sorted by "new" with a length of 10
1629479463718 | Reading posts sorted by "new" with a length of 10
1629479464604 | Reading posts sorted by "new" with a length of 10
1629479465375 | Reading posts sorted by "new" with a length of 10
1629479466383 | Reading posts sorted by "new" with a length of 10
1629479467214 | Reading posts sorted by "new" with a length of 10
1629479467972 | Reading posts sorted by "new" with a length of 10
1629479469168 | Reading posts sorted by "new" with a length of 10
1629479470066 | Reading posts sorted by "new" with a length of 10
1629479470802 | Reading posts sorted by "new" with a length of 10
1629479471542 | Reading posts sorted by "new" with a length of 10
1629479473068 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629554668615 | Dumping config:
1629554668621 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629554672833 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
1629556175766 | Dumping config:
1629556175772 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629556262727 | Reading posts sorted by "new" with a length of 10
1629559886977 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629561256346 | Dumping config:
1629561256352 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629561285920 | Reading posts sorted by "new" with a length of 10
1629561375819 | Trying to set post "undefined", as name "testing for tagz"
1629561375820 | Contents: {"author":"deinz mudda","content":"\thier könnte ihre werbung stehen","create":1629561375819,"desc":"hier nicht","id":-1,"rating":{"+":0,"-":0},"tags":["$$$","othertag"],"title":"testing for tagz"}
1629561412303 | Reading posts sorted by "new" with a length of 10
1629561433206 | Trying to set post "undefined", as name "testing for tagz"
1629561433207 | Contents: {"author":"deinz mudda","content":"\thier könnte ihre werbung stehen","create":1629561433206,"desc":"hier nicht","id":-1,"rating":{"+":0,"-":0},"tags":["$$$","othertag"],"title":"testing for tagz"}
1629561436203 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629562139411 | Dumping config:
1629562139417 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629562148042 | Reading posts sorted by "new" with a length of 10
1629562159432 | Trying to set post "undefined", as name "testing for tagz"
1629562159432 | Contents: {"author":"deinz mudda","content":"\thier könnte ihre werbung stehen","create":1629562159432,"desc":"hier nicht","id":-1,"rating":{"+":0,"-":0},"tags":["$$$","othertag"],"title":"testing for tagz"}
1629562186165 | Trying to set post "undefined", as name "testing for tagz1"
1629562186166 | Contents: {"author":"deinz mudda","content":"\thier könnte ihre werbung stehen","create":1629562186156,"desc":"hier nicht","id":-1,"rating":{"+":0,"-":0},"tags":["$$$","othertag","othertag0"],"title":"testing for tagz1"}
1629562190529 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
1629562432556 | Dumping config:
1629562432562 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629564737518 | Reading posts sorted by "new" with a length of 10
1629564753711 | Reading posts sorted by "new" with a length of 10
1629565127882 | Reading posts sorted by "new" with a length of 10
1629565280896 | Reading posts sorted by "new" with a length of 10
--- SEPERATOR ---
1629565491865 | Dumping config:
1629565491871 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629565492440 | searching stuff by tags "$$$" and sorting "undefined"
--- SEPERATOR ---
1629565531401 | Dumping config:
1629565531407 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629565533680 | searching stuff by tags "$$$" and sorting "undefined"
--- SEPERATOR ---
1629565550028 | Dumping config:
1629565550034 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629565552397 | searching stuff by tags "$$$" and sorting "undefined"
--- SEPERATOR ---
1629565563542 | Dumping config:
1629565563548 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629565565389 | searching stuff by tags "$$$" and sorting "undefined"
1629565581774 | searching stuff by tags "othertag" and sorting "undefined"
1629565586640 | searching stuff by tags "othertag $$$" and sorting "undefined"
1629565845597 | Reading posts sorted by "new" with a length of 10
1629565966893 | Reading posts sorted by "new" with a length of 10
1629565992667 | Reading posts sorted by "new" with a length of 10
1629566309698 | Reading posts sorted by "new" with a length of 10
1629566460490 | searching stuff by tags "$$$" and sorting "undefined"
1629582948025 | Reading posts sorted by "new" with a length of 10
1629582965937 | searching stuff by tags "$$$" and sorting "undefined"
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
--- SEPERATOR ---
1629586094251 | Dumping config:
1629586094256 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629586109664 | searching stuff by tags "$$$" and sorting "undefined"
1629586140819 | searching stuff by tags "$$$" and sorting "undefined"
--- SEPERATOR ---
1629586146024 | Dumping config:
1629586146030 | {"debug":false,"logging":1337,"logfile":"logs/log.log","ipget_endpoint_set":"//derzombiiie.com/getip.php?settoken=${TOKEN}","ipget_endpoint_get":"//derzombiiie.com/getip.php?token=${TOKEN}","cl":true,"site_name":"blog.derzombiiie.com","search_enable":false,"search_only_tags":true,"commenting_enabled":true,"post_ranking_auto":43200,"index_post_sort":"new","comment_sync_on_write":false,"comment_auto_sync":360}
1629586146724 | searching stuff by tags "$$$" and sorting "undefined"
1629586156977 | searching stuff by tags "$$$ testing" and sorting "undefined"
1629586163565 | Reading posts sorted by "new" with a length of 10
1629586168745 | searching stuff by tags "$$$ othertag" and sorting "undefined"
1629586176587 | searching stuff by tags "$$$ othertag" and sorting "undefined"
1629587294373 | Reading posts sorted by "new" with a length of 10
1629587299456 | searching stuff by tags "$$$" and sorting "undefined"
1629587316925 | Reading posts sorted by "new" with a length of 10
1629587444038 | Reading post 1
1629587444689 | Reading comments from post "1", with length: undefined
1629587446984 | Trying to vote on post: 1; and vote: +; iptkn: 2096300560416030; ip: 82.207.236.116;
1629587452705 | Reading posts sorted by "new" with a length of 10
1629587456320 | Reading postindex
1629587456859 | Reading posts sorted by "hot" with a length of 5
1629587475660 | Reading post 2
1629587476646 | Reading comments from post "2", with length: undefined
1629587478649 | Trying to vote on post: 2; and vote: -; iptkn: 4752029791258578; ip: 82.207.236.116;

View File

@ -190,6 +190,7 @@ const postsDB = new JSONdb("storage/posts.json", {
})
posts.init(postsDB)
posts.rank()
posts.index() // for search
// post auto rank
if ( conf.post_auto_rank > 0)
@ -318,6 +319,42 @@ app.all("/comments", (req, res) => { // + rating
}
})
// search stuff:
con.registercmd("search", (arg) => {
if ( !arg[0] || !arg[1] ) return console.log( "No search parameters specified!\nusage: \"search <sort> <param1> <param2>...\"" )
let sort = arg[0]
arg.shift()
console.log( posts.search( arg, sort ) )
})
app.get("/search", (req, res) => {
let tags = req.query.tag.split(" ")
let sort = req.query.sort ? req.query.sort : undefined
if ( req.query.api == undefined ) {
filestuff.readFSr(req, res, "html/search/index.html", "text/html", `""//<!--SEARCH-DATA-INJECT-->//`, JSON.stringify( posts.search( tags, sort, true ) ) )
return
}
log.log( `searching stuff by tags "${req.query.tag}" and sorting "${req.query.sort}"` )
// actual api
res.type("application/json")
if ( req.query.tag == undefined ) {
res.status( 400 )
res.end( JSON.stringify({"type":"err", "text":"No tag provided"}) )
return
}
console.log(req.query)
// check is post info is needed:
let p = req.query.pi != undefined
// construct response
let r = {"type":"s","text":"success!"}
r.content = posts.search( tags, sort, p )
res.end( JSON.stringify( r ) )
})
// debug stuff:
if( conf.debug )
app.get("/debug/:action", (req, res) => {

View File

@ -16,6 +16,7 @@ this.rank = (c) => {
if ( this.db.get(i) ) {
this.postBUFF[i] = this.db.get(i);
} else {
this.len = i
readall = true
}
i++
@ -75,6 +76,9 @@ this.rank = (c) => {
this.read = (count, sort, index) => {
let ret = []
if ( count == -1 ) {
count = this.length
}
switch (sort) {
case "hot":
for ( let i = 0 ; i < count ; i++ ) {
@ -116,6 +120,7 @@ this.push = (post) => {
"title":post.title
})
this.db.set("len", len+1)
this.index()
return {"type":"s","text":"Success! postid: " + len,"content":len}
}
@ -164,3 +169,76 @@ this.rate = ( post, rating, ip ) => {
this.db.set( post , p )
return {"type":"s", "text":"success!", "content": p.rating}
}
// does the indexing for search by tags
this.index = () => {
let len = this.len
this.tags = []
for ( let i = 0 ; i < len ; i++ ) {
this.tags[i] = this.db.get( i ).tags.sort()
}
}
this.search = ( tags, sort, pinfo ) => {
// search goes through all articles and counts the amount of matching tags; then it uses sort to sort stuff though the this.ranking[sort]
let len = this.len
let rnk = []
console.log( len )
// rnk[postID] = amount of matching tags
for ( let l = 0 ; l < len ; l++ ) {
for ( let i = 0 ; i < tags.length ; i++ ) {
if ( this.tags[l].includes( tags[i] ) ) {
console.log(rnk)
if ( !rnk[l] ) {
rnk[l] = 0
}
rnk[l]++
}
}
}
console.log(rnk)
let rem = true
let sorted = []
let pos = -1;
let hig = 0;
while ( rem ) {
for ( let i = 0 ; i < rnk.length ; i++ ) {
if ( rnk[i] ) {
if ( rnk[i] > hig ) {
hig = rnk[i]
pos = i
}
}
}
if ( pos != -1 ) {
sorted.push( pos )
rnk[pos] = undefined
hig = 0
pos = -1
} else {
rem = false
}
}
if ( sort ) {
// do sorting
// another few for loops
}
if ( pinfo ) {
// add post data to response
let ns = []
for ( let i = 0 ; i < sorted.length ; i++ ) {
ns.push( this.db.get( sorted[i] ) )
}
return ns
}
return sorted
}

View File

@ -33,5 +33,14 @@
"body": "This is a test to test\nif the authorinfo works correctly!",
"id": 3
},
"0-len": 4
"0-len": 5,
"0-4": {
"time": 1629373943454,
"author": "94.134.179.144",
"authorinfo": {
"country": "DE",
"origin": "web"
},
"body": "fgaW "
}
}

View File

@ -6,35 +6,51 @@
"content": "# Article!\nwelcome\n*bold***italic** ***bold+italic***\n- point1\n- point2- \n me not more md from the brain :(",
"href": "#",
"tags": [
"testing",
"$$$"
"$$$",
"testing"
],
"dummy": {
"1": 2
},
"rating": {
"+": 999,
"-": 0
"-": 1
},
"create": 2,
"id": 0
},
"1": {
"title": "Warum sind k.rum und was ist k.?",
"author": "olli",
"desc": "Warum nicht! hier text Lorem ipsum dolor sit!",
"href": "#",
"tags": [
"karotte",
"dumm",
"garten"
],
"autor": "deinz mudda",
"content": "\thier könnte ihre werbung stehen",
"create": 1629562159432,
"desc": "hier nicht",
"id": 1,
"rating": {
"+": 395,
"-": 14
"+": 0,
"-": 0
},
"create": 1628252855774,
"id": 1
"tags": [
"$$$",
"othertag"
],
"title": "testing for tagz"
},
"len": 1
"2": {
"autor": "deinz mudda",
"content": "\thier könnte ihre werbung stehen",
"create": 1629562186156,
"desc": "hier nicht",
"id": 2,
"rating": {
"+": 0,
"-": 0
},
"tags": [
"$$$",
"othertag",
"othertag0"
],
"title": "testing for tagz1"
},
"len": 3
}