3

I am using this url to extract data from wikipedia

http://en.wikipedia.org/w/api.php?format=xml&action=query&list=search&srsearch=google&srlimit=1&prop=revisions

This gives snippet as :

Google Inc. is an American multinational corporation specializing in Internet-related services and products. ...

But it is too short.. I want to increase the length of snippet to be returned..

Is there any parameter to specify the length of the snippet..

Thanks,

Vishnu Lal
  • 189
  • 1
  • 4
  • 13
  • 1
    http://www.mediawiki.org/wiki/API:Search does not suggest that this would be possible. – CBroe Mar 22 '13 at 15:18

3 Answers3

3

As far as I know, one cannot directly increase the size of a snippet. But search results can be sent (just in one API call) to TextExtracts which will return more page content.

For example, an API call may look like this:

https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&generator=search&gsrsearch=google&exlimit=max&exintro
Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
  • If I exactly the snippet from all search results (using [continue](https://www.mediawiki.org/wiki/API:Query#Example_4:_Continuing_queries)), only larger, what should the API call look like? And in the mean time are there some other options? – Stoyan Dimitrov Dec 14 '20 at 22:01
1

Replace srlimit=1 to srlimit=50

http://en.wikipedia.org/w/api.php?format=xml&action=query&list=search&srsearch=google&srlimit=50&prop=revisions
Bruno Carvalho
  • 111
  • 2
  • 16
  • thanks for your comment... i want to increase the length of the snippet for each result.. i dont want to increase the count of search result... :) – Vishnu Lal Mar 24 '13 at 15:08
  • sorry, misunderstood the question. made some research on mediawiki and it seems to me its not possible – Bruno Carvalho Mar 25 '13 at 16:50
0

I know this is a dead question, but it's still the first searchresult for this topic so I wanted to share my results.

The culprit lays in the SearchEngine.php where the values are hardcoded.

Source: https://doc.wikimedia.org/mediawiki-core/1.30.0/php/SearchEngine_8php_source.html#l00366

public static function userHighlightPrefs() {
     $contextlines = 2; // Hardcode this. Old defaults sucked. :)
     $contextchars = 75; // same as above.... :P
     return [ $contextlines, $contextchars ];
 }

Since there isn't any hook or similar to override this, my solution was to override the default values, which isn't perfect since I'll have to keep doing this for every new version.

ThermalCube
  • 168
  • 7
  • 13