Skip to content

Commit afda731

Browse files
authored
Merge pull request #40 from catalyst/update_66
Update 66
2 parents e5dbc54 + ad35416 commit afda731

File tree

8 files changed

+318
-53
lines changed

8 files changed

+318
-53
lines changed

.travis.yml

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,74 @@ cache:
1818
- $HOME/.composer/cache
1919

2020
php:
21-
- 5.6
2221
- 7.0
2322
- 7.1
23+
- 7.2
2424

2525
env:
2626
global:
2727
- TEST_SEARCH_ELASTIC_HOSTNAME=http://127.0.0.1
2828
- TEST_SEARCH_ELASTIC_PORT=9200
2929
- TEST_SEARCH_ELASTIC_INDEX=moodle_test
3030
matrix:
31-
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
3231
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
3332
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
3433
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
35-
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
36-
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
37-
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
38-
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
39-
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
40-
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
34+
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
35+
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
4136
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
42-
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
4337
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
4438
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
45-
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
39+
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
40+
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
4641
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
47-
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
4842
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
4943
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
50-
- DB=pgsql MOODLE_BRANCH=master ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
44+
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
45+
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
46+
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
47+
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
48+
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
49+
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
50+
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
5151
- DB=pgsql MOODLE_BRANCH=master ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
52-
- DB=pgsql MOODLE_BRANCH=master ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
5352
- DB=pgsql MOODLE_BRANCH=master ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
5453
- DB=pgsql MOODLE_BRANCH=master ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
54+
- DB=pgsql MOODLE_BRANCH=master ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
55+
- DB=pgsql MOODLE_BRANCH=master ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
5556

5657
matrix:
5758
exclude:
58-
- php: 5.6
59-
env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
60-
- php: 5.6
61-
env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
62-
- php: 5.6
63-
env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
64-
- php: 5.6
65-
env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
66-
- php: 5.6
67-
env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
68-
- php: 5.6
69-
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
70-
- php: 5.6
71-
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
72-
- php: 5.6
73-
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
74-
- php: 5.6
75-
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
76-
- php: 5.6
77-
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
78-
- php: 5.6
79-
env: DB=pgsql MOODLE_BRANCH=master ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
80-
- php: 5.6
81-
env: DB=pgsql MOODLE_BRANCH=master ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
82-
- php: 5.6
83-
env: DB=pgsql MOODLE_BRANCH=master ESVER=5.1.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb
84-
- php: 5.6
85-
env: DB=pgsql MOODLE_BRANCH=master ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
86-
- php: 5.6
87-
env: DB=pgsql MOODLE_BRANCH=master ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
88-
- php: 7.1
89-
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=2.3.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.4/elasticsearch-2.3.4.deb
9059
- php: 7.1
9160
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
9261
- php: 7.1
9362
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
9463
- php: 7.1
9564
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
65+
- php: 7.1
66+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
67+
- php: 7.1
68+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
69+
- php: 7.0
70+
env: DB=pgsql MOODLE_BRANCH=master ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
71+
- php: 7.0
72+
env: DB=pgsql MOODLE_BRANCH=master ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
73+
- php: 7.0
74+
env: DB=pgsql MOODLE_BRANCH=master ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
75+
- php: 7.0
76+
env: DB=pgsql MOODLE_BRANCH=master ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
77+
- php: 7.0
78+
env: DB=pgsql MOODLE_BRANCH=master ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
79+
- php: 7.2
80+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=2.4.4 ESURL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb
81+
- php: 7.2
82+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
83+
- php: 7.2
84+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.0.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.deb
85+
- php: 7.2
86+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.4.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.deb
87+
- php: 7.2
88+
env: DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE ESVER=6.6.1 ESURL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
9689

9790
before_install:
9891
- curl -O ${ESURL} && sudo dpkg -i --force-confnew elasticsearch-${ESVER}.deb && sudo service elasticsearch restart

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@ The following features are provided by this plugin:
1616
This plugin currently supports Moodle:
1717

1818
* 3.1
19-
* 3.3
2019
* 3.4
2120
* 3.5
2221

2322
## Elasticsearch Version Support
2423
Currently this plugin is tested to work against the following versions of Elasticsearch:
2524

26-
* 2.3.4
2725
* 2.4.4
28-
* 5.1.2
2926
* 5.5.0
3027
* 6.0.0
28+
* 6.4.1
29+
* 6.6.1
3130

3231
## Verified Platforms
3332
This plugin has been tested to work on the following cloud platforms:

classes/index_form.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ public function definition() {
8787
$mform->setDefault('sendsize', 9000000);
8888
}
8989

90+
// Search Settings.
91+
$mform->addElement('header', 'searchsettings', get_string('searchsettings', 'search_elastic'));
92+
93+
$mform->addElement(
94+
'advcheckbox',
95+
'wildcardend',
96+
get_string ('wildcardend', 'search_elastic'),
97+
get_string('enable'), array(), array(0, 1));
98+
$mform->setType('wildcardend', PARAM_INT);
99+
$mform->addHelpButton('wildcardend', 'wildcardend', 'search_elastic');
100+
$wildcardend = isset($config->wildcardend) ? $config->wildcardend : 0;
101+
$mform->setDefault('wildcardend', $wildcardend);
102+
103+
$mform->addElement(
104+
'advcheckbox',
105+
'wildcardstart',
106+
get_string ('wildcardstart', 'search_elastic'),
107+
get_string('enable'), array(), array(0, 1));
108+
$mform->setType('wildcardstart', PARAM_INT);
109+
$mform->addHelpButton('wildcardstart', 'wildcardstart', 'search_elastic');
110+
$wildcardstart = isset($config->wildcardstart) ? $config->wildcardstart : 0;
111+
$mform->setDefault('wildcardstart', $wildcardstart);
112+
90113
// Request Signing settings.
91114
$mform->addElement('header', 'signingsettings', get_string('signingsettings', 'search_elastic'));
92115

classes/query.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,70 @@ private function get_search_fields() {
122122
return array_values($searchfields);
123123
}
124124

125+
/**
126+
* Add * wildcard to beginning and/or end of search string if required.
127+
*
128+
* @param string $q The query string.
129+
* @param bool $start Add a wildcard at the start?
130+
* @param bool $end Add a wildcard at the end?
131+
132+
* @return string $q The query string with added wildcards.
133+
*/
134+
private function add_wildcards($q, $start = false, $end = false) {
135+
136+
$terms = explode(" ", $q); // Break search string into individual words.
137+
$wildcardterms = array();
138+
139+
// Add wildcards to start and end of words.
140+
foreach ($terms as $term) {
141+
142+
if (empty($term)) {
143+
continue;
144+
}
145+
146+
$term = str_replace(' ', '', $term);
147+
148+
// Ignore words: and, or.
149+
if (strtolower($term) == 'and' || strtolower($term) == 'or') {
150+
$wildcardterms[] = $term;
151+
continue;
152+
}
153+
154+
if ($start) {
155+
// Add wild card to start of word.
156+
$term = '*' . ltrim($term, '*');
157+
}
158+
159+
if ($end) {
160+
// Add wild card to end of word.
161+
$term = rtrim($term, '*') . '*';
162+
}
163+
164+
$wildcardterms[] = $term;
165+
}
166+
167+
// Reconstruct search query.
168+
if (!empty($wildcardterms)) {
169+
$q = implode(' ', $wildcardterms);
170+
}
171+
172+
return $q;
173+
}
174+
125175
/**
126176
* Takes the search string the user has entered
127177
* and constructs the corresponding part of the
128178
* search query.
129179
*
130-
* @param string $q
180+
* @param string $q The query string.
131181
* @return array
132182
*/
133183
private function construct_q($q) {
184+
$q = $this->add_wildcards(
185+
$q,
186+
get_config('search_elastic', 'wildcardstart'),
187+
get_config('search_elastic', 'wildcardend')
188+
);
134189

135190
$searchfields = $this->get_search_fields();
136191
$qobj = array('query_string' => array('query' => $q, 'fields' => $searchfields));

lang/en/search_elastic.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
$string['imagerecognitionsettingsdesc'] = 'Image recognition extracts details about the content of an image and adds these to the search index.
5454
5555
These settings control what process or service is used to extract data out of an image and how the image data is added to the search engine.';
56+
$string['wildcardstart'] = 'Wildcard at the start';
57+
$string['wildcardstart_help'] = 'When enabled Moodle will add implicit wildcards at the start of search terms. This can improve behaviour of searches.
58+
For example: searching for "scrip" will become "*scrip" prior to be sent to the search engine. This means the search will now match "script" and "description".';
59+
$string['wildcardend'] = 'Wildcard at the end';
60+
$string['wildcardend_help'] = 'When enabled Moodle will add implicit wildcards at the end of search terms. This can improve behaviour of searches.
61+
For example: searching for "math" will become "math*" prior to be sent to the search engine. This means the search will now match "math", "maths" and "mathematics".';
5662
$string['indexfail'] = 'Failed to create index';
5763
$string['maxlabels'] = 'Maxiumum Labels';
5864
$string['maxlabels_help'] = 'The maximum number of result labels returned by Rekognition.';
@@ -84,6 +90,7 @@
8490
Boolean operators (\'AND\', \'OR\') may be used to combine or exclude keywords.
8591
8692
Wildcard characters (\'*\' or \'?\' ) may be used to represent characters in the search query.';
93+
$string['searchsettings'] = 'Search settings';
8794
$string['sendsize'] = 'Request size';
8895
$string['sendsize_help'] = 'Some Elasticsearch providers such as AWS have a limit on how big the HTTP payload can be. Therefore we limit it to a size in bytes.';
8996
$string['signing'] = 'Enable request signing';

0 commit comments

Comments
 (0)