Skip to content

Commit 8d91c12

Browse files
Daniel BerthereauDaniel Berthereau
authored andcommitted
Added an option for partial word / full text search with internal engine (fix #4).
1 parent 16c83c1 commit 8d91c12

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

config/module.config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
],
6969
'form_elements' => [
7070
'invokables' => [
71+
Form\Admin\InternalConfigFieldset::class => Form\Admin\InternalConfigFieldset::class,
7172
Form\Element\ArrayText::class => Form\Element\ArrayText::class,
7273
Form\Element\DataTextarea::class => Form\Element\DataTextarea::class,
7374
Form\Element\Note::class => Form\Element\Note::class,

src/Adapter/InternalAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function getLabel(): string
1313

1414
public function getConfigFieldset(): ?\Laminas\Form\Fieldset
1515
{
16-
return null;
16+
return new \AdvancedSearch\Form\Admin\InternalConfigFieldset;
1717
}
1818

1919
public function getIndexerClass(): string
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AdvancedSearch\Form\Admin;
4+
5+
use Laminas\Form\Element;
6+
use Laminas\Form\Fieldset;
7+
8+
class InternalConfigFieldset extends Fieldset
9+
{
10+
public function init(): void
11+
{
12+
$this
13+
->add([
14+
'name' => 'default_search_partial_word',
15+
'type' => Element\Checkbox::class,
16+
'options' => [
17+
'label' => 'Partial word search for main field (instead of standard full text search)', // @translate
18+
'infos' => 'Currently, this mode does not allow to exclude properties for the main search field.', // @translate
19+
],
20+
'attributes' => [
21+
'id' => 'default_search_partial_word',
22+
],
23+
])
24+
;
25+
}
26+
}

src/Querier/InternalQuerier.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,19 @@ protected function mainQuery(): void
483483
$q = trim($q, '" ');
484484
}
485485

486-
// TODO Use fulltext_search, but when more than 50% results, no results, not understandable by end user (or use boolean mode).
487-
$this->args['property'][] = [
488-
'joiner' => 'and',
489-
'property' => '',
490-
'type' => 'in',
491-
'text' => $q,
492-
];
486+
if ($this->engine->settingAdapter('default_search_partial_word', false)) {
487+
$this->args['property'][] = [
488+
'joiner' => 'and',
489+
'property' => '',
490+
'type' => 'in',
491+
'text' => $q,
492+
];
493+
return;
494+
}
495+
496+
// Full text search is the default Omeka mode.
497+
// TODO It uses fulltext_search, but when more than 50% results, no results, not understandable by end user (or use boolean mode).
498+
$this->args['fulltext_search'] = $q;
493499
}
494500

495501
/**
@@ -508,13 +514,23 @@ protected function mainQueryWithExcludedFields(): void
508514
$q = trim($q, '" ');
509515
}
510516

511-
$this->args['property'][] = [
512-
'joiner' => 'and',
513-
'property' => '',
514-
'except' => $excludedFields,
515-
'type' => 'in',
516-
'text' => $q,
517-
];
517+
pmd(['ici' => $this->engine->settings()]);
518+
// if ($this->getSubSetting('default', ));
519+
520+
if ($this->engine->settingAdapter('default_search_partial_word', false)) {
521+
$this->args['property'][] = [
522+
'joiner' => 'and',
523+
'property' => '',
524+
'except' => $excludedFields,
525+
'type' => 'in',
526+
'text' => $q,
527+
];
528+
return;
529+
}
530+
531+
// Full text search is the default Omeka mode. Exclusion is not possible.
532+
// TODO It uses fulltext_search, but when more than 50% results, no results, not understandable by end user (or use boolean mode).
533+
$this->args['fulltext_search'] = $q;
518534
}
519535

520536
/**

0 commit comments

Comments
 (0)