ranking

Best way to use PostgreSQL full text search ranking

半世苍凉 提交于 2019-12-02 23:29:20
Following on from this answer I want to know what the best way to use PostgreSQL's built-in full text search is if I want to sort by rank, and limit to only matching queries. Let's assume a very simple table. CREATE TABLE pictures ( id SERIAL PRIMARY KEY, title varchar(300), ... ) or whatever. Now I want to search the title field. First I create an index: CREATE INDEX pictures_title ON pictures USING gin(to_tsvector('english', title)); Now I want to search for 'small dog' . This works: SELECT pictures.id, ts_rank_cd( to_tsvector('english', pictures.title), 'small dog' ) AS score FROM pictures

Algorithm to calculate a page importance based on its views / comments

守給你的承諾、 提交于 2019-12-02 17:19:47
I need an algorithm that allows me to determine an appropriate <priority> field for my website's sitemap based on the page's views and comments count. For those of you unfamiliar with sitemaps, the priority field is used to signal the importance of a page relative to the others on the same website. It must be a decimal number between 0 and 1. The algorithm will accept two parameters, viewCount and commentCount , and will return the priority value. For example: GetPriority(100000, 100000); // Damn, a lot of views/comments! The returned value will be very close to 1, for example 0.995

How are Reddit and Hacker News ranking algorithms used?

两盒软妹~` 提交于 2019-12-02 14:15:34
I've been looking at ranking algorithms recently, specifically those used by Reddit and Hacker News. The algorithms themselves are simple enough, but I don't quite understand how they are used. One thing that I could do is implement the algorithm straight in SQL, so that every time a user goes to a page displaying ranked posts, something like this would run: SELECT thing1, thing2 FROM table ORDER BY ranking_algorithm DESC LIMIT page*20, 20 There are several similar questions on SO, but the only answer given is to put the ranking algorithm inside the SQL query. Then the thread dies... Putting

Select TOP N and BOTTOM N

怎甘沉沦 提交于 2019-12-02 09:25:18
Trying to fetch top n bottom n rows. Though it gives me result but, it takes lot of time. I believe it scans table twice. Code used: WITH TI AS (SELECT * FROM (SELECT Column1, Column2, Colmn3 FROM TABLE ORDER BY DESC ) WHERE ROWNUM<=5), T2 AS (SELECT * FROM (SELECT Column1, Column2, Colmn3 FROM TABLE ORDER BY ASC ) WHERE ROWNUM<=5) SELECT * FROM T1 UNION ALL SELECT * FROM T2 How can i fetch this in more faster way?? Considering that tables are updated regularly. The best way to solve this problem depends in part on your Oracle version. Here is a very simple (and, I suspect, very efficient)

Ranking values in a Dictionary (and taking care of ex-aequos correctly)

雨燕双飞 提交于 2019-12-02 09:04:51
问题 I would like to rank the values in a dictionary. For instance, I have this dictionary: {"A": 10, "B: 3, "C": 8, "D": 3, "E": 2} The result should look like: {"E": 1, "B": 2, "D": 2, "C": 4, "A": 5} Please note that D is ranked as fourth because B and D are tied at position two . Hence, there is no position three . Similar solutions have already been given in other threads, however they did not take into account ex-aequo positions in the traditional way: Adding a rank to a dict in python and

Finding the rank of the Given string in list of all possible permutations with Duplicates

怎甘沉沦 提交于 2019-12-02 08:27:56
问题 I was trying to find the Rank of the given string in the list of permutations and was hoping someone can find the bug. function permute() { var W = $('input').val(), C = []; for (var i = 0; i < 26; i++) C[i] = 0; var rank = 1; for (var i = 0; i < W.length; i++) { C[W.charCodeAt(i) - 'a'.charCodeAt(0)]++; } var repeated= 1; for (var i = 0; i < C.length; i++) { if(C[i] > 0) { repeated *= fact(C[i]); } } if (W !== '') { for (var i = 0; i < W.length; i++) { //How many characters which are not

Finding the rank of the Given string in list of all possible permutations with Duplicates

那年仲夏 提交于 2019-12-02 06:38:35
I was trying to find the Rank of the given string in the list of permutations and was hoping someone can find the bug. function permute() { var W = $('input').val(), C = []; for (var i = 0; i < 26; i++) C[i] = 0; var rank = 1; for (var i = 0; i < W.length; i++) { C[W.charCodeAt(i) - 'a'.charCodeAt(0)]++; } var repeated= 1; for (var i = 0; i < C.length; i++) { if(C[i] > 0) { repeated *= fact(C[i]); } } if (W !== '') { for (var i = 0; i < W.length; i++) { //How many characters which are not used, that come before current character var count = 0; for (var j = 0; j < 26; j++) { if (j == (W

Update a MySQL table with record rankings within groups

人走茶凉 提交于 2019-12-02 06:28:09
问题 I have a table called 'winners' with columns 'id', 'category', 'score', 'rank'. I need to update my table and asign a rank within the subcategories (category_id) which as per the sample is 2 but could be more than that in the future. Most anwers I've found are based around select statements which simply tends to just output the table view but I did find a very good 'Update' answer (https://stackoverflow.com/a/2727239/4560380) specifically the answer update where ties are required to share the

Find the ranking of an integer in mysql [duplicate]

人走茶凉 提交于 2019-12-02 03:49:29
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Mysql rank function I have the following countryTable country clicks ------- ------ 0 222 66 34 175 1000 45 650 How do I get the ranking of say country 45 which is 2 in this case? 回答1: Ordered by country ASC : SELECT 1+COUNT(*) AS ranking FROM countryTable WHERE country < 45 ; Ordered by clicks DESC : SELECT 1+COUNT(*) AS ranking FROM countryTable AS t JOIN countryTable AS c ON c.clicks > t.clicks WHERE t

Ranking values in a Dictionary (and taking care of ex-aequos correctly)

久未见 提交于 2019-12-02 02:54:56
I would like to rank the values in a dictionary. For instance, I have this dictionary: {"A": 10, "B: 3, "C": 8, "D": 3, "E": 2} The result should look like: {"E": 1, "B": 2, "D": 2, "C": 4, "A": 5} Please note that D is ranked as fourth because B and D are tied at position two . Hence, there is no position three . Similar solutions have already been given in other threads, however they did not take into account ex-aequo positions in the traditional way: Adding a rank to a dict in python and Python Ranking Dictionary Return Rank First sort the data in ascending order based on the number, like