1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! The [Ana.so](https://ana.so) Algorithm
/// Data used for scoring. Pass into [`score_post`].
/// The static score value to be associated with a post.
///
/// This is made to be run on a post's data whenever
/// a like is added or removed, and put in a score column
/// on the post table.
///
/// As an example (though not the real code):
///
/// ```
/// # use anaso_algorithm::*;
/// # struct PostData {time_posted:i64,likes:i64}
/// # fn query(s:&str,x:i64)->PostData{PostData{time_posted:0,likes:0}}
/// # let id=0;
/// // Get the relevant data for calculating the score
/// let post: PostData = query("SELECT * FROM post WHERE id=?", id);
///
/// // Calculate the new score
/// let score = score_post(ScoringData {
/// time_posted: post.time_posted,
/// likes: post.likes
/// // ...
/// });
///
/// // Update with score
/// query("UPDATE post SET score=? WHERE id=?", id);
/// ```
///
/// When getting posts for a particular page, they will be
/// ordered by this value.
///
/// As an example (though not the real query):
///
/// ```sql
/// SELECT * FROM post ORDER BY score LIMIT=20;
/// ```