Skip to content

Commit

Permalink
Merge pull request #2 from treehouselabs/stemmer
Browse files Browse the repository at this point in the history
Added support for PHP 7 compatible stemmer
  • Loading branch information
pkruithof committed Jan 15, 2016
2 parents c9af36e + 08af84b commit a6a6e73
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# use Docker infrastructure
sudo: false

addons:
apt:
packages:
- libstemmer-dev

cache:
directories:
- $HOME/.composer/cache
Expand All @@ -21,6 +26,17 @@ cache:
directories:
- $HOME/.composer/cache

install:
- sh -c "
git clone https://github.com/jbboehr/php-stemmer.git;
cd php-stemmer && git checkout v1.0.2;
phpize;
./configure;
make;
make install;
"
- echo "extension = stemmer.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
Expand All @@ -29,4 +45,4 @@ script:
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ configuration values, like enums. It also gives you a nice object-oriented way
to handle these.


## Requirements

* PHP >= 5.5
* The stemmer extension: https://github.com/jbboehr/php-stemmer

## Installation

```sh
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
}
],
"require": {
"php": ">=5.5"
"php": ">=5.5",
"ext-stemmer": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"symfony/validator": "~2.4",
"scrutinizer/ocular": "~1.1"
"symfony/validator": "~2.4"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 10 additions & 2 deletions src/TreeHouse/Model/Config/Matcher/Stemmer/PorterStemmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public function __construct($language = 'dutch', $encoding = 'UTF_8')
*/
public function stem($word)
{
return stemword($this->slugify($word), $this->language, $this->encoding);
if (function_exists('stemmer_stem_word')) {
$func = 'stemmer_stem_word';
} elseif (function_exists('stemword')) {
$func = 'stemword';
} else {
throw new \RuntimeException('The php-stemmer extension was not installed/configured properly');
}

return $func($this->slugify($word), $this->language, $this->encoding);
}

/**
Expand Down Expand Up @@ -75,4 +83,4 @@ protected function slugify($slug)
// return rawurlencoded (just to be sure)
return rawurlencode($slug);
}
}
}

0 comments on commit a6a6e73

Please sign in to comment.