Skip to content

Commit

Permalink
FEATURE: Make the article limit for the document strategy configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellienert committed May 22, 2018
1 parent d9958f0 commit 5f93fab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
11 changes: 10 additions & 1 deletion Classes/Api/SearchStrategies/ArticleSearchStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
class ArticleSearchStrategy extends AbstractSearchStrategy
{

/**
* @var int
*/
protected $articleLimit;

public function initializeObject() {
$this->articleLimit = $this->assetSource->getOption('searchStrategyOptions.articleLimit') ?? 10;
}

/**
* @param string $term
* @param int $offset
Expand All @@ -26,7 +35,7 @@ public function search(string $term, int $offset = 0): ImageSearchResult
$articleResultArray = $this->mediaWikiClient->executeQuery([
'list' => 'search',
'srsearch' => $term,
'srlimit' => 10
'srlimit' => $this->articleLimit
]);

return $this->buildImageSearchResult($articleResultArray, $offset);
Expand Down
2 changes: 2 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Neos:
domain: de.wikipedia.org
label: Wikipedia (DE)
searchStrategy: DL\AssetSource\MediaWiki\Api\SearchStrategies\ArticleSearchStrategy
searchStrategyOptions:
articleLimit: 10
useQueryResultCache: true
excludedIdentifierPatterns:
- '*.svg'
Expand Down
19 changes: 13 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Install the package via composer:

You can add arbitrary instances of this asset source, to query different wikimedia instances - e.g. the english and german instance. To do that, just add another configuration block with the specific settings under a custom identifier.

| setting | Description |
| ------------- |-------------|
| domain | The domain on which the MediaWiki instance is available. |
| label | The label of the instance, shown in the backend |
| searchStrategy | A class with implemented search strategy. See the section below for details |
| useQueryResultCache | Whether or not to use the result cache for queries to the API. If used, speeds up the pagination a lot but may return outdated results. The caching lifetime defaults to 1 day. |
| Setting | Description |
| -------------------------- |----------------------|
| domain | The domain on which the MediaWiki instance is available. |
| label | The label of the instance, shown in the backend |
| searchStrategy | A class with implemented search strategy. See the section below for details |
| searchStrategyOptions | Search strategy specific options |
| useQueryResultCache | Whether or not to use the result cache for queries to the API. If used, speeds up the pagination a lot but may return outdated results. The caching lifetime defaults to 1 day. |
| excludedIdentifierPatterns | Asset identifiers which should be filtered out and not displayed. Used to filter out Wikipedias common icons. |

**Example for accessing the german Wikipedia:**
Expand All @@ -33,6 +34,8 @@ You can add arbitrary instances of this asset source, to query different wikimed
domain: de.wikipedia.org
label: Wikipedia (DE)
searchStrategy: DL\AssetSource\MediaWiki\Api\SearchStrategies\ArticleSearchStrategy
searchStrategyOptions:
articleLimit: 10
useQueryResultCache: true
excludedIdentifierPatterns:
- '*.svg'
Expand All @@ -55,6 +58,10 @@ This search strategy uses the filename and available meta data like the descript

This search strategy fits better to the Wikipedia use case. It doesn't search the images directly but uses the more powerfull article search to receive a number of wiki articles and then queries the images shown on that articles. The benefit is, if you configure the domain to `en.wikipedia.org` you will get assets, that are uploaded directly to this instance, as well as all fitting assets uploaded to Wikimedia Commons

| Setting | Description |
| ------------------------- |--------------------------------------------|
| articleLimit | How many articles should be taken into account to query images from. Maximum are 50 articles. Higher values result in more returned articles, but the results may get inaccurate |

## Usage of images in your project

Please take care of the [correct attribution](https://wiki.creativecommons.org/wiki/Best_practices_for_attribution) of used photos in the frontend.
Expand Down

0 comments on commit 5f93fab

Please sign in to comment.