Permalink
Browse files

Make MVEL way faster

Using ".empty" in MVEL is slow when fields are actually empty.  Instead,
use ".isEmpty()".  Against enwiki I measure an order of magnitude performance
improvement on queries that hit lots and lots of results and can't push
the script scoring in the rescore.  3 seconds down to half a second.

Change-Id: Idd394ddc9477fced9130c0aab6f787eb2510f6dc
  • Loading branch information...
Nik Everett
Nik Everett committed Feb 11, 2014
1 parent 6247169 commit d71447266230acfb7b5f0cd72039dfb7ede6845e
Showing with 4 additions and 1 deletion.
  1. +4 −1 includes/Searcher.php
View
@@ -1084,6 +1084,9 @@ private static function lowercaseMatched( $matches ) {
private function installBoosts() {
global $wgCirrusSearchFunctionRescoreWindowSize;
+ // Quick note: At the moment ".isEmpty()" is _much_ faster then ".empty". Never
+ // use ".empty". See https://github.com/elasticsearch/elasticsearch/issues/5086
+
if ( $this->sort !== 'relevance' ) {
// Boosts are irrelevant if you aren't sorting by, well, relevance
return;
@@ -1094,7 +1097,7 @@ private function installBoosts() {
// Customize score by boosting based on incoming links count
if ( $this->boostLinks ) {
- $incomingLinks = "(doc['incoming_links'].empty ? 0 : doc['incoming_links'].value)";
+ $incomingLinks = "(doc['incoming_links'].isEmpty() ? 0 : doc['incoming_links'].value)";
$scoreBoostMvel = "log10($incomingLinks + 2)";
$functionScore->addScriptScoreFunction( new \Elastica\Script( $scoreBoostMvel ) );
$useFunctionScore = true;

0 comments on commit d714472

Please sign in to comment.