/[drupal]/contributions/modules/apachesolr/apachesolr_search.admin.inc
ViewVC logotype

Contents of /contributions/modules/apachesolr/apachesolr_search.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Jun 29 23:23:08 2009 UTC (4 months, 4 weeks ago) by pwolanin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +21 -21 lines
File MIME type: text/x-php
sync with DRUPAL-6--1
1 <?php
2 // $Id: apachesolr_search.admin.inc,v 1.1.2.18 2009/06/09 01:04:39 pwolanin Exp $
3
4 /**
5 * @file
6 * Administrative settings for searching.
7 */
8
9 /**
10 * Menu callback - the settings form.
11 */
12 function apachesolr_search_settings_page() {
13 // try to fetch the schema fields
14 try {
15 $solr = apachesolr_get_solr();
16 $fields = $solr->getFields();
17 $output .= drupal_get_form('apachesolr_search_settings_form', $fields);
18 }
19 catch (Exception $e) {
20 watchdog('apachesolr', nl2br(check_plain($e->getMessage())));
21 drupal_set_message(nl2br(check_plain($e->getMessage())), "warning");
22 $output .= t('Cannot get information about the fields in the index at this time.');
23 }
24 return $output;
25 }
26
27 /**
28 * Menu callback - boosts settings form.
29 */
30 function apachesolr_boost_settings_page() {
31 $output = drupal_get_form('apachesolr_search_bias_form');
32 $output .= drupal_get_form('apachesolr_search_type_boost_form');
33 return $output;
34 }
35
36 /**
37 * Form builder function to set date, comment, etc biases.
38 */
39 function apachesolr_search_bias_form($form_state) {
40
41 $date_settings = variable_get('apachesolr_search_date_boost', '4:200.0');
42 $comment_settings = variable_get('apachesolr_search_comment_boost', '0:0');
43 $changed_settings = variable_get('apachesolr_search_changed_boost', '0:0');
44 $sticky_boost = variable_get('apachesolr_search_sticky_boost', '0');
45 $promote_boost = variable_get('apachesolr_search_promote_boost', '0');
46
47 $options = array(
48 '10:2000.0' => '10',
49 '8:1000.0' => '9',
50 '8:700.0' => '8',
51 '8:500.0' => '7',
52 '4:300.0' => '6',
53 '4:200.0' => '5',
54 '4:150.0' => '4',
55 '2:150.0' => '3',
56 '2:100.0' => '2',
57 '1:100.0' => '1',
58 '0:0' => t('Ignore'),
59 );
60
61 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
62 $weights['0'] = t('Ignore');
63
64 $form['biasing'] = array(
65 '#type' => 'fieldset',
66 '#title' => t('Result biasing'),
67 '#collapsible' => TRUE,
68 '#collapsed' => FALSE,
69 '#description' => t('Give bias to certain properties when ordering the search results. Any value except <em>Ignore</em> will increase the score of the given type in search results. Choose <em>Ignore</em> to ignore any given property.'),
70 );
71 $form['biasing']['apachesolr_search_sticky_boost'] = array(
72 '#type' => 'select',
73 '#options' => $weights,
74 '#title' => t("Sticky at top of lists"),
75 '#default_value' => $sticky_boost,
76 '#description' => t("Select additional bias to give to nodes that are set to be 'Sticky at top of lists'."),
77 );
78 $form['biasing']['apachesolr_search_promote_boost'] = array(
79 '#type' => 'select',
80 '#options' => $weights,
81 '#title' => t("Promoted to home page"),
82 '#default_value' => $promote_boost,
83 '#description' => t("Select additional bias to give to nodes that are set to be 'Promoted to home page'."),
84 );
85 $form['biasing']['apachesolr_search_date_boost'] = array(
86 '#type' => 'select',
87 '#options' => $options,
88 '#title' => t("More recently created"),
89 '#default_value' => $date_settings,
90 '#description' => t('This setting will change the result scoring so that nodes created more recently may appear before those with higher keyword matching.'),
91 );
92 $form['biasing']['apachesolr_search_comment_boost'] = array(
93 '#type' => 'select',
94 '#options' => $options,
95 '#title' => t("More comments"),
96 '#default_value' => $comment_settings,
97 '#description' => t('This setting will change the result scoring so that nodes with more comments may appear before those with higher keyword matching.'),
98 );
99 $form['biasing']['apachesolr_search_changed_boost'] = array(
100 '#type' => 'select',
101 '#options' => $options,
102 '#title' => t("More recent comments"),
103 '#default_value' => $changed_settings,
104 '#description' => t('This setting will change the result scoring so that nodes with the most recent comments (or most recent updates to the node itself) may appear before those with higher keyword matching.'),
105 );
106 $form = system_settings_form($form);
107 $form['biasing']['buttons'] = $form['buttons'];
108 unset($form['buttons']);
109 return $form;
110 }
111
112 /**
113 * Form builder function to set query field weights.
114 */
115 function apachesolr_search_settings_form($form_state, $fields) {
116 $form = array();
117
118 // get the current weights
119 $qf = variable_get('apachesolr_search_query_fields', array());
120 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
121 $weights['0'] = t('Omit');
122 // Note - we have default values set in solrconfig.xml, which will operate when
123 // none are set.
124 $defaults = array(
125 'body' => '1.0',
126 'title' => '5.0',
127 'name' => '3.0',
128 'taxonomy_names' => '2.0',
129 'tags_h1' => '5.0',
130 'tags_h2_h3' => '3.0',
131 'tags_h4_h5_h6' => '2.0',
132 'tags_inline' => '1.0',
133 'tags_a' => '0',
134 );
135 if (!$qf) {
136 $qf = $defaults;
137 }
138 if ($fields) {
139
140 $form['apachesolr_search_query_fields'] = array(
141 '#type' => 'fieldset',
142 '#title' => t('Field biases'),
143 '#collapsible' => TRUE,
144 '#collapsed' => FALSE,
145 '#tree' => TRUE,
146 '#description' => t('Specify here which fields are more important when searching. Give a field a greater numeric value to make it more important. If you omit a field, it will not be searched.'),
147 );
148 foreach ($fields as $field_name => $field) {
149 $form['apachesolr_search_query_fields'][$field_name] = array(
150 '#access' => $field->type == 'text',
151 '#type' => 'select',
152 '#options' => $weights,
153 '#title' => apachesolr_field_name_map($field_name),
154 '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : '0',
155 );
156 }
157 // Make sure all the default fields are included, even if they have no indexed content.
158 foreach ($defaults as $field_name => $weight) {
159 $form['apachesolr_search_query_fields'][$field_name] = array(
160 '#type' => 'select',
161 '#options' => $weights,
162 '#title' => apachesolr_field_name_map($field_name),
163 '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : $defaults[$field_name],
164 );
165 }
166
167 ksort($form['apachesolr_search_query_fields']);
168 }
169
170 return system_settings_form($form);
171 }
172
173 /**
174 * Form builder function to set query type weights.
175 */
176 function apachesolr_search_type_boost_form($form_state) {
177 $form = array();
178
179 $form['apachesolr_search_type_settings'] = array(
180 '#type' => 'fieldset',
181 '#title' => t('Type biasing and exclusion'),
182 '#collapsible' => TRUE,
183 '#collapsed' => FALSE,
184 );
185 $form['apachesolr_search_type_settings']['apachesolr_search_type_boosts'] = array(
186 '#type' => 'item',
187 '#description' => t("Specify here which node types should get a higher relevancy score in searches. Any value except <em>Ignore</em> will increase the score of the given type in search results."),
188 '#tree' => TRUE,
189 );
190
191 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
192 $weights['0'] = t('Ignore');
193
194 // Get the current boost values.
195 $type_boosts = variable_get('apachesolr_search_type_boosts', array());
196 $names = node_get_types('names');
197
198 foreach ($names as $type => $name) {
199 $form['apachesolr_search_type_settings']['apachesolr_search_type_boosts'][$type] = array(
200 '#type' => 'select',
201 '#title' => t('%type type content bias', array('%type' => $name)),
202 '#options' => $weights,
203 '#default_value' => isset($type_boosts[$type]) ? $type_boosts[$type] : 0,
204 );
205 }
206
207 $form['apachesolr_search_type_settings']['apachesolr_search_excluded_types'] = array(
208 '#type' => 'checkboxes',
209 '#title' => t('Types to exclude from the search index'),
210 '#options' => $names,
211 '#default_value' => variable_get('apachesolr_search_excluded_types', array()),
212 '#description' => t("Specify here which node types should be totally excluded from the search index. Content excluded from the index will never appear in any search results."),
213 );
214
215 $form['#submit'][] = 'apachesolr_search_type_boost_form_submit';
216 $form = system_settings_form($form);
217 $form['apachesolr_search_type_settings']['buttons'] = $form['buttons'];
218 unset($form['buttons']);
219 return $form;
220 }
221
222 /**
223 * Submit callback for apachesolr_search_type_boost_form().
224 *
225 * This is called before system_settings_form_submit().
226 */
227 function apachesolr_search_type_boost_form_submit($form_id, &$form_state) {
228 $old_excluded_types = variable_get('apachesolr_search_excluded_types', array());
229 $new_excluded_types = $form_state['values']['apachesolr_search_excluded_types'];
230 // Check whether we are resetting the values.
231 if ($form_state['clicked_button']['#value'] == t('Reset to defaults')) {
232 $new_excluded_types = array();
233 }
234
235 foreach ($new_excluded_types as $type => $excluded) {
236 // Remove newly omitted node types.
237 // Note - we omit a check on empty($old_excluded_types[$type]) so that
238 // the admin can re-submit this page if the delete operation fails.
239 if (!empty($new_excluded_types[$type])) {
240 $solr = apachesolr_get_solr();
241 $solr->deleteByQuery("type:$type");
242 apachesolr_index_updated(time());
243 }
244 }
245
246 foreach ($old_excluded_types as $type => $excluded) {
247 // Set no longer omitted node types for reindexing.
248 if (empty($new_excluded_types[$type]) && !empty($old_excluded_types[$type])) {
249 db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE nid IN (SELECT nid FROM {node} WHERE type = '%s')", time(), $type);
250 }
251 }
252 }

  ViewVC Help
Powered by ViewVC 1.1.2