Skip to content

Commit

Permalink
Feature parity with SearchWP Finnish Base Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
joppuyo committed Aug 11, 2018
1 parent 223d022 commit e80f714
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 244 deletions.
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,58 @@

Relevanssi plugin to add Finnish base forms into search index using [Voikko](https://voikko.puimula.org/).

You can either use **Node.js application** to access Voikko over HTTP or use a locally installed **voikkospell command line application** to lemmatize the indexed terms. Special thanks to [siiptuo](https://github.com/siiptuo) for contributing voikkospell support for this plugin!
## What does it do?

The CLI application is much faster because it doesn't have the overhead performing a HTTP request.
This plugin allows you to add base forms of Finnish words in Relevanssi search index. For example for word *koirillekin*, tokens *koirillekin* and *koira* are saved in the index during indexing. Learn mode by reading [this article](https://www.creuna.com/fi/ajankohtaista/wordpress-haku-searchwp-voikko/) (in Finnish).

## Options

### API type

You can use bundled **voikkospell binary** (on a linux x64 system) to lemmatize the indexed terms.

There is also an option to use a system-wide **voikkospell command line application** if you have Voikko installed on your system.

It's also possible to set up an external **Node.js API** to access Voikko over HTTP. Using the binary or CLI application is much faster because it doesn't have the overhead of performing a HTTP request.

Special thanks to [siiptuo](https://github.com/siiptuo) for contributing voikkospell support for this plugin!

### Add base forms to search query

Enable this option to add base forms to search queries entered by users.

### Split compound words

Enable this option to split compound words during indexing (and for user queries if the above option is enabled). For example, the word *kerrostaloille* is transformed into tokens *kerrostaloille*, *kerrostalo*, *kerros* and *talo* in the search index.

## Requirements

* Relevanssi 4.0.4 or later
* PHP 5.5.9
* A server with either Node.js and about 1GB of spare RAM or voikkospell command line application installed
* PHP 5.5.9 or later
* One of the following:
* A x64 Linux server
* A server with voikkospell command line application installed
* A server with Node.js and about 1GB of spare RAM

## Installation

1. Clone this plugin into **wp-content/plugins**
2. Go to **wp-content/plugins/relevanssi-finnish-base-forms** and run **composer install**
3. **Activate** Relevanssi Finnish Base Forms from your Plugins page
1. **Download** latest version from the [releases](https://github.com/joppuyo/relevanssi-finnish-base-forms/releases) tab
2. **Unzip** the plugin into your `wp-content/plugins` directory
3. **Activate** SearchWP Finnish Base Forms from your Plugins page

### Node.js web API
### Bundled voikkospell binary

1. Install and start [Voikko Node.js web API](https://github.com/joppuyo/voikko-node-web-api).
2. Go on the Plugins page, find the plugin, click **Settings** and enter the Node API URL there
1. Go on the Plugins page, find the plugin, click **Settings**. For **API Type** select **Voikko binary (bundled)**.

### Voikkospell command line

1. Install voikkospell on your server. On Ubuntu/Debian this can be done with `apt install libvoikko-dev voikko-fi`
2. Go on the Plugins page, find the plugin, click **Settings**. For **API Type** select **Voikko command line**.

### Node.js web API

1. Install and start [Voikko Node.js web API](https://github.com/joppuyo/voikko-node-web-api).
2. Go on the Plugins page, find the plugin, click **Settings** and enter the Node API URL there

After installation, remember to re-index the site from Relevanssi settings page.

19 changes: 19 additions & 0 deletions bin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License for voikkospell and Voikko dictionary

## Voikkospell (part of libvoikko)

[https://github.com/voikko/corevoikko/tree/master/libvoikko](https://github.com/voikko/corevoikko/tree/master/libvoikko)

GNU GPL v3.0 or later

## Voikko-fi

[https://github.com/voikko/corevoikko/tree/master/voikko-fi](https://github.com/voikko/corevoikko/tree/master/voikko-fi)

GNU GPL v2.0 or later

## Binaries

[https://github.com/siiptuo/voikko-build](https://github.com/siiptuo/voikko-build)

GNU GPL v3.0 or later
Binary file added bin/dictionary/5/mor-standard/autocorr.vfst
Binary file not shown.
10 changes: 10 additions & 0 deletions bin/dictionary/5/mor-standard/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Voikko-Dictionary-Format: 5
Language: fi-x-standard
Copyright: 2006-2017 Hannu Väisänen, Harri Pitkänen, Teemu Likonen and others
License: GPL version 2 or later
Description: suomi (perussanasto)
SM-Version: 2.2
SM-Patchinfo:
Build-Config: GENLEX_OPTS= EXTRA_LEX=
Build-Date: Sat, 04 Aug 2018 18:51:58 +0000
Morphology-Backend: finnishVfst
Binary file added bin/dictionary/5/mor-standard/mor.vfst
Binary file not shown.
Binary file added bin/voikkospell
Binary file not shown.
84 changes: 42 additions & 42 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
(function ($) {
var update = function () {
if ($('input[name=api_type]:checked').val() === 'command_line') {
$('.js-relevanssi-finnish-base-forms-api-url').hide();
} else {
$('.js-relevanssi-finnish-base-forms-api-url').show();
}
$('.js-relevanssi-finnish-base-forms-test-output').html('');
};
$(document).ready(function () {
update();
$('input[name=api_type]').change(function () {
update();
});
$('.js-relevanssi-finnish-base-forms-form').submit(function (event) {
var self = this;
event.preventDefault();
$('.js-relevanssi-finnish-base-forms-submit-button').attr('disabled', true);
var data = {
action: 'relevanssi_finnish_base_forms_test',
};
if ($('input[name=api_type]:checked').val() === 'command_line') {
data.api_type = 'command_line';
} else {
data.api_type = 'web_api';
data.api_root = $('input[name=api_url]').val();
}
$.post(ajaxurl, data)
.done(function() {
$('.js-relevanssi-finnish-base-forms-submit-button').attr('disabled', false);
self.submit();
})
.fail(function() {
window.scrollTo(0, 0);
$('.js-relevanssi-finnish-base-forms-submit-button').attr('disabled', false);
$('.notice.notice-success').remove();
$('.js-relevanssi-finnish-base-forms-admin-notices').html(
'<div class="notice notice-error">' +
'<p>Failed to connect the Voikko API. Make sure Voikko has been correctly installed.</p>' +
'</div>'
);
var update = function () {
if ($('input[name=api_type]:checked').val() === 'binary' || $('input[name=api_type]:checked').val() === 'command_line') {
$('.js-finnish-base-forms-api-url').hide();
} else {
$('.js-finnish-base-forms-api-url').show();
}
};
$(document).ready(function () {
update();
$('input[name=api_type]').change(function () {
update();
});
$('.js-finnish-base-forms-form').submit(function (event) {
var self = this;
event.preventDefault();
$('.js-finnish-base-forms-submit-button').attr('disabled', true);
var slug = $('.js-finnish-base-forms-form').data('slug');
var data = {
action: slug + '_finnish_base_forms_test',
};
if ($('input[name=api_type]:checked').val() === 'command_line' || $('input[name=api_type]:checked').val() === 'binary') {
data.api_type = $('input[name=api_type]:checked').val();
} else {
data.api_type = 'web_api';
data.api_root = $('input[name=api_url]').val();
}
$.post(ajaxurl, data)
.done(function() {
$('.js-finnish-base-forms-submit-button').attr('disabled', false);
self.submit();
})
.fail(function() {
window.scrollTo(0, 0);
$('.js-finnish-base-forms-submit-button').attr('disabled', false);
$('.notice.notice-success').remove();
$('.js-finnish-base-forms-admin-notices').html(
'<div class="notice notice-error">' +
'<p>Failed to connect the Voikko API. Make sure Voikko has been correctly installed.</p>' +
'</div>'
);
});
});
});
});
})(jQuery);
})(jQuery);
12 changes: 8 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
Contributors: joppuyo
Tags: relevanssi, finnish, stem, stemming, lemmatization, lemmatisation
Requires at least: 4.9.4
Tested up to: 4.9.4
Tested up to: 4.9.8
Requires PHP: 5.5.9 or greater
License: License: GPLv3 or later

Relevanssi plugin to add Finnish base forms in search index

== Description ==
Relevanssi plugin to add Finnish base forms in search index. Requires Node.js and Relevanssi 4.0.4 or later.
Relevanssi plugin to add Finnish base forms in search index. Requires Relevanssi 4.0.4 or later.

== Installation ==
1. Clone this plugin into **wp-content/plugins**
2. **Activate** Relevanssi Finnish Base Forms from your Plugins page
3. Either install Node.js application or voikkospell command line application
4. Configure plugin in **Plugins** and **Settings** under Relevanssi Finnish Base Forms
3. Configure plugin in **Plugins** and **Settings** under Relevanssi Finnish Base Forms

== Changelog ==

= 1.1.0 =
* Add option to split compound words
* Add option to use bundled voikkospell binary on Linux systems

= 1.0.0 =
* Initial release
Loading

0 comments on commit e80f714

Please sign in to comment.