User:Mattsmith321/Page rank

This is to document the work on better sorting for SphinxSearch results. Current default is to sort by sphinx internal weight, which is calculated based on number of matches within the text, whether they are in the title or in the body, etc. This is how it would be possible to also sort by number of incoming links to the article and article popularity.

SphinxQL
The Sphinx search engine has two main interfaces: the API and SphinxQL. The SphinxSearch extension is built on the Sphinx API. SphinxQL is useful for running queries from the command-line to see raw results and data. SphinxQL is another way of querying Sphinx. It uses the MySQL 4.1 transport protocol and for this reason no API is required, any MySQL client can be used instead. SphinxQL is an SQL subset, similar to MySQL. See From API to SphinxQL and Back Again additional information.

NOTE: These instructions are specific to a Windows installation. /* Sun Sep 22 10:08:42.274 2013 conn 1 wall 0.001 found 2884 */ SELECT * FROM wiki_main,wiki_incremental WHERE MATCH('msis') AND page_namespace=0 AND page_is_redirect=0;
 * Set up SphinxQL by making the following changes to the sphinx.conf file in the # searchd settings:
 * Restart the MySQL and Sphinx services to pick up the changes.
 * Perform a search in the wiki application and verify that the SphinxQL output was logged in the query_log file specified:
 * Connect to MySQL via the MySQLSphinxQL port:


 * Run the SphinxQL from the query_log output file:

Basic example
The example below will sort results first by Sphinx weight, but after that by number of links TO that article and by number of article views. Feel free to experiment with the order of these arguments, or to add additional ones.

In sphinx.conf file, source src_wiki_main section, after this line:

sql_query_pre = SET NAMES utf8

ADD another query that creates a temporary table with incoming link counts:

CHANGE sql_query attribute to pick this data up, and also to get page_counter field which stores numbers of article hits:

ADD two new attributes to the list below the query:

sql_attr_uint  = page_counter sql_attr_uint  = pl_count

CHANGE sql_query in source src_wiki_incremental section to match the main query (your query page_touched... part may vary, and note that we are moving rev_id=page_latest and old_id=rev_text_id from WHERE to INNER JOINs)

Reindex your wikis and add this to LocalSettings.php after the SphinxSearch.php inclusion:

Advanced example
The example below shows how to add even more custom columns