https://bugzilla.wikimedia.org/show_bug.cgi?id=25931
--- Comment #26 from Asher Feldman <[email protected]> 2012-04-27 01:25:46 UTC --- How to implement a category based random feature in wikipedia without touching the database: 1) Send lucene an incategory query with a limit of 1 to cheaply get the total number of articles indexed in the given category. Stuff this in memcache with a reasonable ttl (couple hours?) and try to grab there next time so lucene is only called once. 2) Send the same category with an offset of rand(0, $doc_count - 1) 3) Redirect to the article returned in step 2. Command line example to get a random "Domestic animals" article. Step one - the very first item in the response is the match count (36 in this case): asher@bast1001:~/srchtest$ curl 'http://search1001:8123/search/enwiki/incategory:%22Domesticated%20animals%22?limit=1' 36 #info search=[search1001,search1001], highlight=[search1004] in 4 ms #no suggestion #interwiki 0 0 #results 1 12.586081 0 Genomics_of_domestication #h.text [] [] [+] date+November+2011 #h.text [] [] [] Genomics+is+the+study+of+the+structure%2C+content%2C+and+evolution++of+genomes+%2C+or+the+entire+genetic+information+of+ #h.date 2012-04-04T12:25:13Z #h.wordcount 2252 #h.size 15955 Step two - pick a random number between 0 - 35.. let's go with 16. asher@bast1001:~/srchtest$ curl 'http://search1001:8123/search/enwiki/incategory:%22Domesticated%20animals%22?offset=16&limit=1' 36 #info search=[search1001,search1001], highlight=[search1005] in 3 ms #no suggestion #interwiki 0 0 #results 1 6.2930403 0 Fancy_pigeon #h.text [] [] [+] Fancy+pigeons+are+domesticated++varieties+of+the+Rock+Pigeon++%28Columba+livia%29.+ #h.text [] [] [] They+are+bred+by+pigeon+fanciers++for+various+traits+ #h.date 2012-02-21T12:23:54Z #h.wordcount 903 #h.size 7354 Hi, Fancy Pigeon! -- Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. You are on the CC list for the bug. _______________________________________________ Wikibugs-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/wikibugs-l
