https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113475

Revision: 113475
Author:   maxsem
Date:     2012-03-09 15:54:44 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
Bug 35083 - OpenSearchXml first sentences extraction produces bad results. Made 
extracts at least 100 characters long (configurable).

Modified Paths:
--------------
    trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
    trunk/extensions/OpenSearchXml/OpenSearchXml.php

Modified: trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php
===================================================================
--- trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php 2012-03-09 15:49:28 UTC 
(rev 113474)
+++ trunk/extensions/OpenSearchXml/ApiOpenSearchXml.php 2012-03-09 15:54:44 UTC 
(rev 113475)
@@ -275,6 +275,7 @@
         * @access private
         */
        function extractStart( $text ) {
+               global $wgOpenSearchDescriptionLength;
                $endchars = array(
                        '([^\d])\.\s', '\!\s', '\?\s', // regular ASCII
                        '。', // full-width ideographic full-stop
@@ -284,7 +285,7 @@
 
                $endgroup = implode( '|', $endchars );
                $end = "(?:$endgroup)";
-               $sentence = ".*?$end+";
+               $sentence = ".{{$wgOpenSearchDescriptionLength},}?$end+";
                $firstone = "/^($sentence)/u";
                $matches = array();
                if( preg_match( $firstone, $text, $matches ) ) {

Modified: trunk/extensions/OpenSearchXml/OpenSearchXml.php
===================================================================
--- trunk/extensions/OpenSearchXml/OpenSearchXml.php    2012-03-09 15:49:28 UTC 
(rev 113474)
+++ trunk/extensions/OpenSearchXml/OpenSearchXml.php    2012-03-09 15:54:44 UTC 
(rev 113475)
@@ -40,6 +40,11 @@
 $wgOpenSearchAdvertiseXml = true;
 
 /**
+ * Minimum length of extract in <Description>. Actual extracts will last until 
the end of sentence.
+ */
+$wgOpenSearchDescriptionLength = 100;
+
+/**
  * @param $urls array
  * @return bool
  */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to