forked from Islandora/islandora_solr_views
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_solr_views.views.inc
141 lines (126 loc) · 4.12 KB
/
islandora_solr_views.views.inc
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file
* This file contains views definitions. Defines views and data/field types.
*/
/**
* Implements hook_views_plugins().
*/
function islandora_solr_views_views_plugins() {
return array(
'module' => 'islandora_solr_views',
'query' => array(
'islandora_solr_views_query' => array(
'title' => t('Islandora Solr Query'),
'help' => t('Query that allows you to search Islandora Solr.'),
'handler' => 'islandora_solr_views_query',
'parent' => 'views_query',
),
),
);
}
/**
* Implements hook_views_data().
*/
function islandora_solr_views_views_data() {
// Set base variables.
$base_field = 'PID';
$base_table = 'islandora_solr';
$data[$base_table]['table']['group'] = t('Islandora Solr');
$data[$base_table]['table']['base'] = array(
'query class' => 'islandora_solr_views_query',
'title' => t('Islandora Solr'),
'help' => t('Searches the Islandora Solr index.'),
'field' => $base_field,
);
// Get the list of the fields in index directly from Solr.
$luke = islandora_solr_get_luke();
$solr_fields = $luke['fields'];
// Always add score handlers.
$data[$base_table]['score'] = array(
'title' => t('Score'),
'help' => t('Relevancy score'),
'field' => array(
'handler' => 'islandora_solr_views_handler_field',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'islandora_solr_views_handler_argument',
),
'filter' => array(
'handler' => 'islandora_solr_views_handler_filter',
),
'sort' => array(
'handler' => 'islandora_solr_views_handler_sort',
),
);
// Include object manage link.
$data[$base_table]['islandora_manage'] = array(
'title' => t('Manage link'),
'help' => t('Provide a simple link to manage the content.'),
'field' => array(
'handler' => 'islandora_solr_views_handler_field_manage',
),
);
// Include a lucene query parser filter (q).
$data[$base_table]['query_lucene'] = array(
'title' => t('Query Parser (Lucene)'),
'help' => t('Query Parser field to perform Lucene keyword searches.'),
'filter' => array(
'handler' => 'islandora_solr_views_handler_filter_query_lucene',
),
);
// Include a dismax query parser filter (q).
$data[$base_table]['query_dismax'] = array(
'title' => t('Query Parser (DisMax)'),
'help' => t('Query Parser field to perform DisMax keyword searches.'),
'filter' => array(
'handler' => 'islandora_solr_views_handler_filter_query_dismax',
),
);
// Loop over all solr fields.
foreach ($solr_fields as $solr_field_name => $solr_field) {
// We do not allow to display 'sort_*' fields.
if (strpos($solr_field_name, 'sort_') === 0) {
continue;
}
// Set luke field variables.
$field_type = $solr_field['type'];
$field_schema = $solr_field['schema'];
$field_dynamicbase = isset($solr_field['dynamicBase']) ? $solr_field['dynamicBase'] : NULL;
// Set field handlers.
$field = array();
$field['title'] = $solr_field_name;
$field['help'] = t('Type') . ': ' . $field_type;
// Field handler.
if ($field_type == 'date') {
$field['field']['handler'] = 'islandora_solr_views_handler_field_date';
}
else {
$field['field']['handler'] = 'islandora_solr_views_handler_field';
}
// Check if sortable.
if (strstr($field_schema, "I") != FALSE AND strstr($field_schema, "M") == FALSE) {
$field['field']['click sortable'] = TRUE;
}
// Argument handler.
$field['argument'] = array(
'handler' => 'islandora_solr_views_handler_argument',
);
// Filter handler.
$field['filter'] = array(
'handler' => 'islandora_solr_views_handler_filter',
);
// Sortable handler.
// Check if sortable: must be indexed and can't be multivalued.
// http://wiki.apache.org/solr/CommonQueryParameters#sort
if (strstr($field_schema, "I") != FALSE AND strstr($field_schema, "M") == FALSE) {
$field['sort'] = array(
'handler' => 'islandora_solr_views_handler_sort',
);
}
// Add array.
$data[$base_table][$solr_field_name] = $field;
}
return $data;
}