$this->db = $db;
}
- /** @todo document */
+ /**
+ * Parse the user's query and transform it into an SQL fragment which will
+ * become part of a WHERE clause
+ */
function parseQuery( $filteredText, $fulltext ) {
global $wgContLang;
$lc = SearchEngine::legalSearchChars(); // Minus format chars
function queryNamespaces() {
if( is_null($this->namespaces) )
return ''; # search all
- $namespaces = implode( ',', $this->namespaces );
- if ($namespaces == '') {
+ if ( !count( $this->namespaces ) ) {
$namespaces = '0';
+ } else {
+ $namespaces = $this->db->makeList( $this->namespaces );
}
return 'AND page_namespace IN (' . $namespaces . ')';
}
function queryNamespaces() {
if( is_null($this->namespaces) )
return '';
- $namespaces = implode(',', $this->namespaces);
- if ($namespaces == '') {
+ if ( !count( $this->namespaces ) ) {
$namespaces = '0';
+ } else {
+ $namespaces = $this->db->makeList( $this->namespaces );
}
return 'AND page_namespace IN (' . $namespaces . ')';
}
'WHERE page_id=si_page AND ' . $match;
}
- /** @todo document */
+ /**
+ * Parse a user input search string, and return an SQL fragment to be used
+ * as part of a WHERE clause
+ */
function parseQuery($filteredText, $fulltext) {
global $wgContLang;
$lc = SearchEngine::legalSearchChars();
}
}
- $searchon = $this->db->strencode(join(',', $q));
+ $searchon = $this->db->addQuotes(join(',', $q));
$field = $this->getIndexField($fulltext);
- return " CONTAINS($field, '$searchon', 1) > 0 ";
+ return " CONTAINS($field, $searchon, 1) > 0 ";
}
/**
/*
* Transform the user's search string into a better form for tsearch2
+ * Returns an SQL fragment consisting of quoted text to search for.
*/
function parseQuery( $term ) {
}
$prefix = $wgDBversion < 8.3 ? "'default'," : '';
+ # Get the SQL fragment for the given term
$searchstring = $this->parseQuery( $term );
## We need a separate query here so gin does not complain about empty searches
if ( count($this->namespaces) < 1)
$query .= ' AND page_namespace = 0';
else {
- $namespaces = implode( ',', $this->namespaces );
+ $namespaces = $this->db->makeList( $this->namespaces );
$query .= " AND page_namespace IN ($namespaces)";
}
}
function update( $pageid, $title, $text ) {
## We don't want to index older revisions
$SQL = "UPDATE pagecontent SET textvector = NULL WHERE old_id IN ".
- "(SELECT rev_text_id FROM revision WHERE rev_page = $pageid ".
- "ORDER BY rev_text_id DESC OFFSET 1)";
+ "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval( $pageid ) .
+ " ORDER BY rev_text_id DESC OFFSET 1)";
$this->db->doQuery($SQL);
return true;
}