-
Notifications
You must be signed in to change notification settings - Fork 2
/
strawberry_runners.module
66 lines (61 loc) · 2.35 KB
/
strawberry_runners.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @file
* Contains strawberryfield.module.
*/
use Drupal\Core\Utility\Error as ErrorAlias;
use Drupal\search_api\Entity\Index;
/**
* Implements hook_views_data_alter().
*/
function strawberry_runners_views_data_alter(array &$data) {
//@see search_api_views_data()
/** @var \Drupal\search_api\IndexInterface $index */
foreach (Index::loadMultiple() as $index) {
try {
$key = 'search_api_index_' . $index->id();
$table = &$data[$key];
$ml_image_filter = _search_api_views_find_field_alias('sbr_imageml_filter', $table);
$ml_text_filter = _search_api_views_find_field_alias('sbr_textml_filter', $table);
$table[$ml_image_filter] = [
'title' => t('Image Similarity Filter via KNN (Experimental)'),
'group' => t('Search'),
'help' => t('Filters one or more Images belonging to an ADO against the Corresponding Vector in a Strawberry Flavor Document generating on the Fly an Embedding Vector.'),
'filter' => [
'title' => t('Image Similarity Filter via KNN '),
'field' => 'id',
'id' => 'sbr_imageml_filter',
],
'argument' => [
'title' => t('Image Similarity Filter via KNN '),
'field' => 'id',
'id' => 'sbr_imageml_filter',
'disable_break_phrase' => TRUE, // Disallows multiple values for ML fields
],
];
if ($ml_image_filter != 'sbr_imageml_filter') {
$table[$ml_image_filter]['real field'] = 'sbr_imageml_filter';
}
$table[$ml_text_filter] = [
'title' => t('Text Similarity Filter via KNN (Experimental)'),
'group' => t('Search'),
'help' => t('Filters one Query Phrases to the Corresponding Vector in a Strawberry Flavor Document generating on the Fly an Embedding Vector.'),
'filter' => [
'title' => t('Text Similarity Filter via KNN '),
'field' => 'id',
'id' => 'sbr_textml_filter',
],
];
if ($ml_text_filter != 'sbr_textml_filter') {
$table[$ml_image_filter]['real field'] = 'sbr_textml_filter';
}
}
catch (\Exception $e) {
$args = [
'%index' => $index->label(),
];
ErrorAlias::logException('strawberry_runners', $e, '%type while computing Views data for index %index: @message in %function (line %line of %file).', $args);
}
}
return $data;
}