| 1 |
<?php
|
| 2 |
|
| 3 |
/*
|
| 4 |
* Copyright (C) 2007 Jonathan Hendler
|
| 5 |
*
|
| 6 |
* This program is free software; you can redistribute it and/or
|
| 7 |
* modify it under the terms of the GNU General Public License
|
| 8 |
* as published by the Free Software Foundation; either version 2
|
| 9 |
* of the License, or (at your option) any later version.
|
| 10 |
*
|
| 11 |
* This program is distributed in the hope that it will be useful,
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
* GNU General Public License for more details.
|
| 15 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with this program; if not, write to the Free Software
|
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
| 19 |
*
|
| 20 |
* The author can be contacted at:
|
| 21 |
* - jonathan [at] civicactions (dot) com
|
| 22 |
*
|
| 23 |
* @license http://www.affero.org/oagpl.html
|
| 24 |
* @link http://drupal.org/project/semantic_search
|
| 25 |
*/
|
| 26 |
|
| 27 |
|
| 28 |
/**
|
| 29 |
* used for creating searches
|
| 30 |
* */
|
| 31 |
function semantic_search_search_form($search_name = null){
|
| 32 |
$form = array();
|
| 33 |
$default_values = array();
|
| 34 |
global $_semantic_search_search;
|
| 35 |
if (empty ($_semantic_search_search))
|
| 36 |
_SEMANTIC_SEARCH_INIT();
|
| 37 |
//use cache?
|
| 38 |
|
| 39 |
//get default values
|
| 40 |
if (!empty($search_name)){
|
| 41 |
$default_values = _semantic_search_get_search_form_vars($search_name);
|
| 42 |
}//end empty search name
|
| 43 |
|
| 44 |
//cache control for this search
|
| 45 |
$form['cache_settings'] = array (
|
| 46 |
'#type' => 'fieldset',
|
| 47 |
'#title' => 'Cache Settings',
|
| 48 |
'#description' => t('Settings for indexing and caching.'),
|
| 49 |
'#collapsible' => 1,
|
| 50 |
'#collapsed' => 1
|
| 51 |
);
|
| 52 |
|
| 53 |
|
| 54 |
$form['cache_settings']['sf_use_cache'.$search_name] = array (
|
| 55 |
'#type' => 'checkbox',
|
| 56 |
'#title' => t('Use Cache'),
|
| 57 |
'#description' => t('Cache can build organically with use, or you can build here.'),
|
| 58 |
'#return_value' => 1,
|
| 59 |
'#default_value' => variable_get('sf_use_cache'.$search_name,0),
|
| 60 |
);
|
| 61 |
|
| 62 |
|
| 63 |
$form['main_search_settings'] = array (
|
| 64 |
'#type' => 'fieldset',
|
| 65 |
'#title' => 'Main Settings',
|
| 66 |
'#description' => t('Main Settings for Creating or Modifying a Search'),
|
| 67 |
'#collapsible' => 1,
|
| 68 |
'#collapsed' => 1
|
| 69 |
);
|
| 70 |
|
| 71 |
$attributes = array();
|
| 72 |
if (!empty($search_name) && $search_name != '') {
|
| 73 |
$attributes = array('disabled'=>1);
|
| 74 |
|
| 75 |
$form['main_search_settings']['search_id'] = array (
|
| 76 |
'#type' => 'hidden',
|
| 77 |
'#value' => $default_values['id'],
|
| 78 |
);
|
| 79 |
|
| 80 |
}
|
| 81 |
|
| 82 |
$form['main_search_settings']['search_name'] = array (
|
| 83 |
'#type' => 'textfield',
|
| 84 |
'#title' => t('Search Name'),
|
| 85 |
'#description' => t('<strong>VERY IMPORTANT</strong> readable name like "animals", "birds", or "fish" .<br/>' .
|
| 86 |
'Is used for the cache name, index name, rdf tables name etc.'),
|
| 87 |
'#default_value' => $search_name,
|
| 88 |
'#attributes' => $attributes,
|
| 89 |
);
|
| 90 |
|
| 91 |
$form['main_search_settings']['search_path'] = array (
|
| 92 |
'#type' => 'textfield',
|
| 93 |
'#title' => t('Search Path'),
|
| 94 |
'#description' => t('The url for users to access the search. Eg <code>search/myanimals</code>'),
|
| 95 |
'#default_value' => $default_values['path'] );
|
| 96 |
|
| 97 |
$options = array('default'=>'default','custom api'=>'custom api','syndicated'=>'syndicated',);
|
| 98 |
|
| 99 |
$form['main_search_settings']['search_type'] = array (
|
| 100 |
'#type' => 'select',
|
| 101 |
'#title' => t('Search Type'),
|
| 102 |
'#options' => $options,
|
| 103 |
'#description' => t('<ul>' .
|
| 104 |
'<li><strong>default</strong>: a default interface. Can be themed.</li>' .
|
| 105 |
'<li><strong>custom api</strong>: creates an API available for RPC calls. </li>' .
|
| 106 |
'<li><strong>syndicated</strong>: custom module for aggregating content dynamically.</li>' .
|
| 107 |
'</ul>'),
|
| 108 |
'#default_value' => $default_values['type'] );
|
| 109 |
|
| 110 |
$options = array('arc_local'=>'default ARC local','arc_remote'=>'ARC remote','sesame_remote'=>'Sesame Remote',);
|
| 111 |
$form['main_search_settings']['search_store_type'] = array (
|
| 112 |
'#type' => 'select',
|
| 113 |
'#title' => t('Store Type'),
|
| 114 |
'#options' => $options,
|
| 115 |
'#description' => t('<ul>' .
|
| 116 |
'<li><strong>default ARC local</strong>: this is the only store available. Uses ARC locally</li>' .
|
| 117 |
'<li><strong>ARC remote</strong>: TODO: ARC on another server. </li>' .
|
| 118 |
'<li><strong>Sesame Remote</strong>: TODO Sesame on another server</li>' .
|
| 119 |
'</ul>'),
|
| 120 |
'#default_value' => $default_values['store_type'] );
|
| 121 |
|
| 122 |
//TODO store type
|
| 123 |
$form['main_search_settings']['search_title'] = array (
|
| 124 |
'#type' => 'textfield',
|
| 125 |
'#title' => t('Search Title'),
|
| 126 |
'#description' => t('The human-friendly, display name for the search. Like "My Search", or "Animals"'),
|
| 127 |
'#default_value' => $default_values['title'] );
|
| 128 |
|
| 129 |
$form['main_search_settings']['search_description'] = array (
|
| 130 |
'#type' => 'textarea',
|
| 131 |
'#rows' => 5,
|
| 132 |
'#title' => t('Search Description'),
|
| 133 |
'#description' => t('Description of the search.'),
|
| 134 |
'#default_value' => $default_values['description']
|
| 135 |
);
|
| 136 |
|
| 137 |
|
| 138 |
$form['data_settings'] = array (
|
| 139 |
'#type' => 'fieldset',
|
| 140 |
'#title' => 'Data Settings',
|
| 141 |
'#description' => t('Settings for what Drupal data will be searched.'),
|
| 142 |
'#collapsible' => 1,
|
| 143 |
'#collapsed' => 1
|
| 144 |
);
|
| 145 |
|
| 146 |
$form['data_settings']['NODE_SYNC'] = array (
|
| 147 |
'#type' => 'checkbox',
|
| 148 |
'#title' => t('<strong>NODE SYNC</strong>'
|
| 149 |
), '#description' => t('Select node and data types below. All data and related taxonomy terms will' .
|
| 150 |
' be imported and indexed. This could take a VERY long time.'),
|
| 151 |
'#return_value' => 1,
|
| 152 |
'#default_value' => 0,);
|
| 153 |
|
| 154 |
$form['data_settings']['NODE_RESET'] = array (
|
| 155 |
'#type' => 'checkbox',
|
| 156 |
'#title' => t('<strong>Clear Search Cache and RDF data.</strong>'
|
| 157 |
), '#description' => t('Also, clear ALL the data in SEMANTIC_SEARCH - only use this when starting over!!!'), '#return_value' => 1, '#default_value' => 0,
|
| 158 |
'#attributes'=>array('disabled'=>'disabled'));
|
| 159 |
|
| 160 |
$index_size = _semantic_search_node_index_count();
|
| 161 |
$total_node_count = _semantic_search_node_total_count();
|
| 162 |
$the_type = 'SEMANTIC_SEARCH_IMPORT_BATCH_SIZE';
|
| 163 |
$form['data_settings'][$the_type] = array (
|
| 164 |
'#type' => 'textfield',
|
| 165 |
'#title' => t('Batch Size'
|
| 166 |
), '#description' => t('There are currently %size of %total total nodes imported this search.<br>It takes a long time to build RDF. This lets you build in batches.',
|
| 167 |
array('%size'=>$index_size,'%total'=>$total_node_count)),
|
| 168 |
//'#return_value' => 1,
|
| 169 |
'#default_value' => variable_get($the_type, 1000),
|
| 170 |
'#attributes'=>array('disabled'=>'disabled'));
|
| 171 |
|
| 172 |
$type_options = _content_type_info();
|
| 173 |
//dbg($type_options,'$type_options');
|
| 174 |
|
| 175 |
$form['data_settings']['div_begin_a']['#value'] = '<div id="cck-options">';
|
| 176 |
|
| 177 |
$form['data_settings']['CCK Sync'] = array (
|
| 178 |
'#type' => 'fieldset',
|
| 179 |
'#title' => 'Node Syncronization ',
|
| 180 |
);
|
| 181 |
|
| 182 |
$search_type_select = array();
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
foreach ($type_options['content types'] as $id => $data) {
|
| 187 |
$pref_name = 'display_' . $id;
|
| 188 |
$label = $data['name'];
|
| 189 |
$description = $data['description'];
|
| 190 |
$fields = $data['fields'];
|
| 191 |
|
| 192 |
$search_type_select['all_'.$id] = t('All fields of ').$label;
|
| 193 |
|
| 194 |
$form['data_settings']['CCK Sync'][$pref_name] = array (
|
| 195 |
'#type' => 'checkbox',
|
| 196 |
'#title' => t('Store CCK type <strong>' . $label . '</strong> in SEMANTIC_SEARCH.'
|
| 197 |
), '#description' => t('Should CCK type <em>' . $label . ' (' . $description . ')</em> be stored in SEMANTIC_SEARCH to be available for RDF search and export"?'),
|
| 198 |
'#return_value' => 1,
|
| 199 |
'#default_value' => variable_get($pref_name, '0'),);
|
| 200 |
|
| 201 |
if (!empty ($fields)) {
|
| 202 |
|
| 203 |
$form['data_settings']['CCK Sync'][$pref_name . '_f'] = array (
|
| 204 |
'#type' => 'fieldset',
|
| 205 |
'#title' => $label . ' Field Options ',
|
| 206 |
'#collapsible' => 1,
|
| 207 |
'#collapsed' => 1,
|
| 208 |
'#description' => t('Should CCK field the field display in the search results?'),
|
| 209 |
);
|
| 210 |
|
| 211 |
foreach ($fields as $fid => $field_data) {
|
| 212 |
|
| 213 |
$pref_name2 = 'display_result_' . $fid;
|
| 214 |
$pref_name3 = 'display_result_weight' . $fid;
|
| 215 |
|
| 216 |
$field_label = $field_data['widget']['label'];
|
| 217 |
|
| 218 |
$search_type_select[$id.'=>'.$fid] = $field_label;
|
| 219 |
|
| 220 |
$field_id = $fid;
|
| 221 |
|
| 222 |
|
| 223 |
$form['data_settings']['CCK Sync'][$pref_name . '_f'][$pref_name2] = array (
|
| 224 |
'#type' => 'checkbox',
|
| 225 |
'#title' => str_replace('_field_label',$field_label,t('_field_label : Display in search Results?')),
|
| 226 |
'#description' => t(''),
|
| 227 |
'#return_value' => 1,
|
| 228 |
'#default_value' => variable_get($pref_name2, '4'),);
|
| 229 |
|
| 230 |
$form['data_settings']['CCK Sync'][$pref_name . '_f'][$pref_name3] = array (
|
| 231 |
'#type' => 'select',
|
| 232 |
'#options' => array (
|
| 233 |
|
| 234 |
0=>str_replace('_field_label',$field_label,t('Weight') ),
|
| 235 |
-5,
|
| 236 |
-4,
|
| 237 |
-3,
|
| 238 |
-2,
|
| 239 |
-1,
|
| 240 |
1,
|
| 241 |
2,
|
| 242 |
3,
|
| 243 |
4,
|
| 244 |
5
|
| 245 |
), '#default_value' => variable_get($pref_name3, 0),);
|
| 246 |
|
| 247 |
//file settings
|
| 248 |
$furi = SONIA_PROPERTY_ID_URI . $fid;
|
| 249 |
$is_file_type = $_semantic_search_search->sonia->isFileType($furi);
|
| 250 |
if ($is_file_type) {
|
| 251 |
$file_pref_name = 'display_image_' . $fid;
|
| 252 |
$form['data_settings']['CCK Sync'][$pref_name . '_f'][$file_pref_name] = array (
|
| 253 |
'#type' => 'checkbox',
|
| 254 |
'#title' => t('Display field <em>"' . $field_label . '"</em> in SEMANTIC_SEARCH search results as image.'
|
| 255 |
), '#description' => t('Should CCK field <em>' . $field_label . ' </em> display in the search results as an image?'), '#return_value' => 1, '#default_value' => variable_get($file_pref_name, '0'),);
|
| 256 |
}
|
| 257 |
|
| 258 |
}
|
| 259 |
}
|
| 260 |
//get cck fields and have a setting for
|
| 261 |
//show in search results
|
| 262 |
} //end cck types foreach
|
| 263 |
|
| 264 |
$form['data_settings']['div_end_a']['#value'] = '</div>';
|
| 265 |
|
| 266 |
//node types/ cck types // users / relationships // node relation
|
| 267 |
|
| 268 |
$form['default_search_settings'] = array (
|
| 269 |
'#type' => 'fieldset',
|
| 270 |
'#title' => 'Default Interface Settings',
|
| 271 |
'#description' => t('Settings for "default" and "module" interface searches. '),
|
| 272 |
'#collapsible' => 1,
|
| 273 |
'#collapsed' => 1
|
| 274 |
);
|
| 275 |
|
| 276 |
// number of search results to display on a page
|
| 277 |
$form['default_search_settings']['SF_DISPLAY_PAGINATION'.$search_name] = _semantic_search_form_element(
|
| 278 |
'SF_DISPLAY_PAGINATION'.$search_name,
|
| 279 |
'Number of Results',
|
| 280 |
'Number of search results to show per page.',
|
| 281 |
10);
|
| 282 |
|
| 283 |
$description_a = (empty($search_name)) ? t('Create the search form here, after the search has been created.'): t('Create the search form here.');
|
| 284 |
|
| 285 |
//get list of fields with search
|
| 286 |
$form['default_search_settings']['search_form'] = array(
|
| 287 |
'#type' => 'fieldset',
|
| 288 |
'#title' => 'The Search Form',
|
| 289 |
'#description' => t('Create the search form here.'),
|
| 290 |
'#collapsible' => 1,
|
| 291 |
'#collapsed' => 1
|
| 292 |
);
|
| 293 |
|
| 294 |
if(!empty($search_name)){
|
| 295 |
|
| 296 |
//list search fields
|
| 297 |
$search_fields = _semantic_search_get_form_search_fields( $default_values['id']);
|
| 298 |
//drupal_set_message( print_r($search_fields,1));
|
| 299 |
|
| 300 |
$header = array( t('Facet Name'),t('Description'),'','');
|
| 301 |
$data = array();
|
| 302 |
|
| 303 |
$attr = array('title'=> t('Edit Search Facet of '). $search_name);
|
| 304 |
$list = array();
|
| 305 |
|
| 306 |
foreach($search_fields as $key=> $search_field){
|
| 307 |
$data[$key][] = $title = t($search_field['title']);
|
| 308 |
$data[$key][] = t($search_field['description']);
|
| 309 |
|
| 310 |
$fid = $search_field['id'];
|
| 311 |
|
| 312 |
$link = url(SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/edit/'.$fid,null,null,true);
|
| 313 |
$data[$key][] = l(t('Edit'),$link,$attr) ;
|
| 314 |
|
| 315 |
$link = url(SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/delete',null,null,true);
|
| 316 |
$data[$key][] = l(t('Delete'),$link,$attr);
|
| 317 |
|
| 318 |
}
|
| 319 |
|
| 320 |
$form['default_search_settings']['search_form']['edit_fields'] = array(
|
| 321 |
'#value' => theme('table',$header,$data)
|
| 322 |
);
|
| 323 |
|
| 324 |
//link
|
| 325 |
$attr = array('title'=> t('Add Search Facet to '). $search_name);
|
| 326 |
$link = url(SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/add',null,null,true);
|
| 327 |
$form['default_search_settings']['search_form']['add_field'] = array(
|
| 328 |
'#value' => l(t('Add Facet'),$link,$attr) ,
|
| 329 |
);
|
| 330 |
|
| 331 |
}
|
| 332 |
|
| 333 |
$form['import'] = array (
|
| 334 |
'#type' => 'fieldset',
|
| 335 |
'#title' => 'Import',
|
| 336 |
// '#description' => t('Settings for indexing and caching.'),
|
| 337 |
'#collapsible' => 1,
|
| 338 |
'#collapsed' => 1
|
| 339 |
);
|
| 340 |
|
| 341 |
$form['export'] = array (
|
| 342 |
'#type' => 'fieldset',
|
| 343 |
'#title' => 'Export',
|
| 344 |
// '#description' => t('Settings for indexing and caching.'),
|
| 345 |
'#collapsible' => 1,
|
| 346 |
'#collapsed' => 1
|
| 347 |
);
|
| 348 |
|
| 349 |
|
| 350 |
//////////////////////////////////////////////////
|
| 351 |
$word = ($search_name !== null) ? t('Update') : t('Create');
|
| 352 |
|
| 353 |
$form['end']['submit'] = array (
|
| 354 |
'#type' => 'submit',
|
| 355 |
'#value'=>$word);
|
| 356 |
|
| 357 |
if($search_name !== null){
|
| 358 |
$form['end']['delete'] = array (
|
| 359 |
'#type' => 'submit',
|
| 360 |
'#value'=> t('Delete'));
|
| 361 |
}
|
| 362 |
|
| 363 |
return $form;
|
| 364 |
}
|
| 365 |
|
| 366 |
/**
|
| 367 |
*
|
| 368 |
* */
|
| 369 |
function semantic_search_search_field_form($search_name, $field_id = null, $edit = false){
|
| 370 |
global $_semantic_search_search;
|
| 371 |
if (empty ($_semantic_search_search))
|
| 372 |
_SEMANTIC_SEARCH_INIT();
|
| 373 |
|
| 374 |
//select cck types for this search
|
| 375 |
// get allowed fields
|
| 376 |
//describe what is needed
|
| 377 |
$description = t('These choices are based on what is selectedat the <a href="@a">search admin page</a>',array('@a'=>''));
|
| 378 |
$warning = '';
|
| 379 |
$warning = t('You must first select fields at the <a href="@a">search admin page</a>',array('@a'=>''));
|
| 380 |
$default_values = $form = array();
|
| 381 |
$search_data = _semantic_search_get_search_form_vars($search_name);
|
| 382 |
|
| 383 |
$search_id = $search_data['id'];
|
| 384 |
$form['field_settings'] = array (
|
| 385 |
'#type' => 'fieldset',
|
| 386 |
'#title' => 'Field Configuration',
|
| 387 |
'#description' => t('Settings for an individual Facet to search on'),
|
| 388 |
);
|
| 389 |
|
| 390 |
if ($edit){
|
| 391 |
//get default values
|
| 392 |
$default_values = _semantic_search_get_form_search_field($field_id);
|
| 393 |
|
| 394 |
$form['field_settings']['id'] = array (
|
| 395 |
'#type' => 'hidden',
|
| 396 |
'#value' => $field_id,
|
| 397 |
);
|
| 398 |
}
|
| 399 |
|
| 400 |
|
| 401 |
$form['field_settings']['search_id'] = array (
|
| 402 |
'#type' => 'hidden',
|
| 403 |
'#value' => $search_id,
|
| 404 |
);
|
| 405 |
|
| 406 |
|
| 407 |
//**posible URIs (based on CCK fields?)
|
| 408 |
$form['field_settings']['title'] = array (
|
| 409 |
'#type' => 'textfield',
|
| 410 |
'#title' => t('Title'),
|
| 411 |
'#description' => t('In a select this can show as the first option, or a label. In other form elements, it is a label.'),
|
| 412 |
'#default_value' => (isset($default_values['title'])) ? $default_values['title']: '',
|
| 413 |
);
|
| 414 |
|
| 415 |
$form['field_settings']['description'] = array (
|
| 416 |
'#type' => 'textarea',
|
| 417 |
'#rows' => 3,
|
| 418 |
'#title' => t('Description'),
|
| 419 |
'#description' => t('Same as the forms_api #description'),
|
| 420 |
'#default_value' => (isset($default_values['description'])) ? $default_values['description']: '',
|
| 421 |
);
|
| 422 |
|
| 423 |
$uri_options = $_semantic_search_search->getAllBaseOptions();
|
| 424 |
|
| 425 |
$form['field_settings']['uris'] = array (
|
| 426 |
'#type' => 'select',
|
| 427 |
'#options' => $uri_options,
|
| 428 |
'#title' => t('URI'),
|
| 429 |
'#description' => t('In this list is the Node type, Taxonomy, or Node Field. For Semantic Search these are translated to RDF as Property, or RDF classes, or literals.'),
|
| 430 |
'#default_value' => (isset($default_values['uris'])) ? $default_values['uris']: '',
|
| 431 |
);
|
| 432 |
|
| 433 |
$options = array('select'=>'Select','links'=>'Links','checkbox'=>'Checkboxes',);
|
| 434 |
|
| 435 |
$form['field_settings']['form_type'] = array (
|
| 436 |
'#type' => 'select',
|
| 437 |
'#options' => $options,
|
| 438 |
'#title' => t('Form Field Type'),
|
| 439 |
'#description' => t('Standard HTML elements'),
|
| 440 |
'#default_value' => (isset($default_values['form_type'])) ? $default_values['form_type']: 0,
|
| 441 |
);
|
| 442 |
|
| 443 |
$options = array('p_value'=>'Property Value','class'=>'Class','property'=>'Property','fulltext'=>'Full Text',);
|
| 444 |
$form['field_settings']['search_field_type'] = array (
|
| 445 |
'#type' => 'select',
|
| 446 |
'#options' => $options,
|
| 447 |
'#title' => t('Search Field Type'),
|
| 448 |
'#description' => t(' '),
|
| 449 |
'#default_value' => (isset($default_values['search_field_type'])) ? $default_values['search_field_type']: 0,
|
| 450 |
);
|
| 451 |
|
| 452 |
$form_element_options_state['#type'] = 'select';
|
| 453 |
$form_element_options_state['#query_type'] = 'p_value';
|
| 454 |
$form_element_options_state['#multiple_facet'] = false;
|
| 455 |
$form_element_options_state['#show_in_search_count'] = true;
|
| 456 |
|
| 457 |
|
| 458 |
// uris text utf8_unicode_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
|
| 459 |
// form_type varchar(32) utf8_unicode_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
|
| 460 |
// search_field_type varchar(32) utf8_unicode_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
|
| 461 |
|
| 462 |
|
| 463 |
// top_option int(1) UNSIGNED No Browse distinct values Change Drop Primary Unique Index Fulltext
|
| 464 |
//
|
| 465 |
$form['field_settings']['title_as_option'] = array (
|
| 466 |
'#type' => 'checkbox',
|
| 467 |
'#title' => t('Title as option'),
|
| 468 |
'#description' => t(''),
|
| 469 |
'#return_value' => 1,
|
| 470 |
'#default_value' => (isset($default_values['title_as_option'])) ? $default_values['title_as_option']: 0,
|
| 471 |
);
|
| 472 |
|
| 473 |
$form['field_settings']['grand_total'] = array (
|
| 474 |
'#type' => 'checkbox',
|
| 475 |
'#title' => t('Display Grand Total with top Option'),
|
| 476 |
'#description' => t(''),
|
| 477 |
'#return_value' => 1,
|
| 478 |
'#default_value' => (isset($default_values['grand_total'])) ? $default_values['grand_total']: 0,
|
| 479 |
);
|
| 480 |
|
| 481 |
$form['field_settings']['multiple'] = array (
|
| 482 |
'#type' => 'checkbox',
|
| 483 |
'#title' => t('Multiple Facet'),
|
| 484 |
'#description' => t('Allow users to select multiple fields from this facet.'),
|
| 485 |
'#return_value' => 1,
|
| 486 |
'#default_value' => (isset($default_values['multiple'])) ? $default_values['multiple']: 1,
|
| 487 |
);
|
| 488 |
|
| 489 |
$word = ($edit) ? t('Update') : t('Create');
|
| 490 |
|
| 491 |
$form['end']['submit'] = array (
|
| 492 |
'#type' => 'submit',
|
| 493 |
'#value'=>$word);
|
| 494 |
|
| 495 |
if($search_name !== null){
|
| 496 |
$form['end']['delete'] = array (
|
| 497 |
'#type' => 'submit',
|
| 498 |
'#value'=> t('Delete'));
|
| 499 |
}
|
| 500 |
return $form;
|
| 501 |
}
|
| 502 |
|
| 503 |
function _semantic_search_get_search_name($search_id){
|
| 504 |
return db_result(db_query("SELECT name FROM {semantic_search_searches} WHERE id=%d LIMIT 1",$search_id));
|
| 505 |
}
|
| 506 |
|
| 507 |
/**
|
| 508 |
*
|
| 509 |
* */
|
| 510 |
function semantic_search_search_field_form_submit($form_id, $form_values){
|
| 511 |
$fid = _semantic_search_set_search_field_vars($form_values);
|
| 512 |
$search_name = _semantic_search_get_search_name($form_values['search_id']);
|
| 513 |
return SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/edit/'.$fid;
|
| 514 |
}
|
| 515 |
|
| 516 |
function semantic_search_search_field_form_validate($form_id, $form_values){
|
| 517 |
$title = $form_values['title'];
|
| 518 |
if (empty($title)){
|
| 519 |
form_set_error('title', t('The field needs a name.'));
|
| 520 |
}
|
| 521 |
}
|
| 522 |
|
| 523 |
/**
|
| 524 |
* implementation of hook_submit
|
| 525 |
* */
|
| 526 |
function semantic_search_search_form_submit($form_id,$form_values){
|
| 527 |
$op = $form_values['op'];
|
| 528 |
$search_name = _semantic_search_set_search_form_vars($form_values, $op);
|
| 529 |
|
| 530 |
|
| 531 |
if ($op == t('Create')){
|
| 532 |
$number_of_results_var = 'SF_DISPLAY_PAGINATION';
|
| 533 |
} else {
|
| 534 |
$number_of_results_var = 'SF_DISPLAY_PAGINATION'.$search_name;
|
| 535 |
}
|
| 536 |
$number_of_results = $form_values[$number_of_results_var];
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
//Array ( [sf_use_cache] => 0 [search_name] => adsfasdf [search_path] => asdfadsf/adfads [search_type] => default [search_title] => adfad [search_description] => adsfad [NODE_SYNC] => 0 [NODE_RESET] => 0 [SEMANTIC_SEARCH_IMPORT_BATCH_SIZE] => 1000 [display_page] => 0 [display_story] => 0 [SF_DISPLAY_PAGINATION] => 10 [op] => Create [submit] => Create [form_token] => cd2e25e6f40acb08683455279eb6fb8c [form_id] => semantic_search_search_form )
|
| 541 |
|
| 542 |
//node sync and reset?
|
| 543 |
if (isset ($form_values['CCK_SYNC']) && ($form_values['CCK_SYNC'] == 1)) {
|
| 544 |
drupal_set_message(t('Semantic Search: synchronizing with CCK'));
|
| 545 |
_semantic_search_node_sync($form_values);
|
| 546 |
}
|
| 547 |
|
| 548 |
//caching? probably over RPC
|
| 549 |
|
| 550 |
drupal_set_message(print_r($form_values,1));
|
| 551 |
|
| 552 |
return SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name;
|
| 553 |
}
|
| 554 |
|
| 555 |
|
| 556 |
/**
|
| 557 |
* implementation of hook_submit
|
| 558 |
* */
|
| 559 |
function semantic_search_search_form_validate($form_id,$form_values){
|
| 560 |
$op = $form_values['op'];
|
| 561 |
$search_name = $form_values['search_name'];
|
| 562 |
$search_path = $form_values['search_path'];
|
| 563 |
$search_title = $form_values['search_title'];
|
| 564 |
|
| 565 |
if (empty($search_name)){
|
| 566 |
form_set_error('search_name', t('The search needs a name.'));
|
| 567 |
} else if ( $op == 'Create' && _semantic_search_get_search_form_vars($search_name) ){
|
| 568 |
//check if name is taken
|
| 569 |
form_set_error('search_name', t('The search name was taken.'));
|
| 570 |
}
|
| 571 |
|
| 572 |
if (empty($search_title)){
|
| 573 |
form_set_error('search_name', t('The search needs a title.'));
|
| 574 |
}
|
| 575 |
|
| 576 |
if ($op == t('Create')){
|
| 577 |
$number_of_results_var = 'SF_DISPLAY_PAGINATION';
|
| 578 |
} else {
|
| 579 |
$number_of_results_var = 'SF_DISPLAY_PAGINATION'.$search_name;
|
| 580 |
}
|
| 581 |
|
| 582 |
$number_of_results = $form_values[$number_of_results_var];
|
| 583 |
|
| 584 |
if (empty($number_of_results) || !is_numeric($number_of_results)){
|
| 585 |
form_set_error($number_of_results_var, t('Search must return at least 1 result.'));
|
| 586 |
}
|
| 587 |
|
| 588 |
if (empty($search_path)){
|
| 589 |
form_set_error('search_path', t('The search needs a path.'));
|
| 590 |
}
|
| 591 |
}
|
| 592 |
|
| 593 |
|
| 594 |
/**
|
| 595 |
*
|
| 596 |
* */
|
| 597 |
function _semantic_search_form_element($the_type,$title,$description = '',$default=''){
|
| 598 |
$element = array();
|
| 599 |
//$the_type = 'semantic_search_search_form_title';
|
| 600 |
$element[$the_type] = array (
|
| 601 |
'#type' => 'textfield',
|
| 602 |
'#title' => t($title),
|
| 603 |
'#description' => t($description),
|
| 604 |
//'#return_value' => 1,
|
| 605 |
'#default_value' => variable_get($the_type,$default),);
|
| 606 |
|
| 607 |
return $element;
|
| 608 |
}
|
| 609 |
|
| 610 |
//TODO move to per config
|
| 611 |
|
| 612 |
|
| 613 |
/**
|
| 614 |
* base URL should match waht is in settings.php
|
| 615 |
* */
|
| 616 |
_semantic_search_def('_BASE_URL', 'http://ahirc');
|
| 617 |
|
| 618 |
/**
|
| 619 |
* base URI for data specific to the site
|
| 620 |
* */
|
| 621 |
_semantic_search_def('_BASE_NAMESPACE_URL', 'http://www.ahirc.org');
|
| 622 |
|
| 623 |
/***
|
| 624 |
* prints debugging stuff to screen
|
| 625 |
* (currently disabled)
|
| 626 |
*/
|
| 627 |
_semantic_search_def('SEMANTIC_SEARCH_DEBUG', true);
|
| 628 |
|
| 629 |
/**
|
| 630 |
* Width of text search forms
|
| 631 |
* */
|
| 632 |
_semantic_search_def('SEMANTIC_SEARCH_TEXT_INPUT_FORM_WIDTH', 25);
|
| 633 |
|
| 634 |
/**
|
| 635 |
* number of search results to display on a page
|
| 636 |
* */
|
| 637 |
_semantic_search_def('SEMANTIC_SEARCH_DISPLAY_PAGINATION', 10);
|
| 638 |
|
| 639 |
/**
|
| 640 |
* display search
|
| 641 |
* */
|
| 642 |
_semantic_search_def('SEMANTIC_SEARCH_DISPLAY_SEARCH_COUNTS', true);
|
| 643 |
|
| 644 |
/**
|
| 645 |
* display totals for item
|
| 646 |
* */
|
| 647 |
_semantic_search_def('SEMANTIC_SEARCH_DISPLAY_TOTAL_COUNTS', true);
|
| 648 |
|
| 649 |
/**
|
| 650 |
* display only one count and not both
|
| 651 |
* */
|
| 652 |
_semantic_search_def('SEMANTIC_SEARCH_DISPLAY_SINGLE_COUNT', false);
|
| 653 |
|
| 654 |
define('SONIA_DEBUG', true);
|
| 655 |
/* location of an error log */
|
| 656 |
//define('SONIA_ERROR_LOG','/Temp/SONIAERROR.txt');
|
| 657 |
//define('SONIA_WRITE_ARC_LOG', true);
|
| 658 |
//define('SONIA_ARC_LOG_PATH', SONIA_LOCAL_ARC_TOOLS.'/logs/');
|
| 659 |
|
| 660 |
/**
|
| 661 |
* datatabase that ARC uses
|
| 662 |
* */
|
| 663 |
_semantic_search_def('ARC_DB_NAME', '');
|
| 664 |
|
| 665 |
/**
|
| 666 |
* ARC DB username
|
| 667 |
* */
|
| 668 |
_semantic_search_def('ARC_DB_USER', '');
|
| 669 |
|
| 670 |
/**
|
| 671 |
* ARC DB password
|
| 672 |
* */
|
| 673 |
_semantic_search_def('ARC_DB_PW', '');
|
| 674 |
|
| 675 |
/**
|
| 676 |
* ARC DB host
|
| 677 |
* */
|
| 678 |
_semantic_search_def('ARC_DB_HOST', 'localhost');
|
| 679 |
|
| 680 |
/**
|
| 681 |
* ARC DB port... should be 3306 in most cases
|
| 682 |
* */
|
| 683 |
_semantic_search_def('ARC_DB_PORT', 3306);
|
| 684 |
|
| 685 |
/**
|
| 686 |
* table name prefix to use in case using the same DB which has non - arc tables
|
| 687 |
* */
|
| 688 |
_semantic_search_def('ARC_DB_PREFIX_NAME', 'semantic_search');
|
| 689 |
|
| 690 |
/**
|
| 691 |
* simple function wrapper for defines
|
| 692 |
* */
|
| 693 |
function _semantic_search_def($title, $default = '') {
|
| 694 |
if (defined($title))
|
| 695 |
watchdog('semantic_search', "$title already defined in _semantic_search_def()", WATCHDOG_WARNING);
|
| 696 |
define($title, variable_get($title, $default));
|
| 697 |
}
|
| 698 |
|
| 699 |
function _semantic_search_get_search_form_vars($search_name){
|
| 700 |
return db_fetch_array(db_query("SELECT * FROM {semantic_search_searches} WHERE name='%s' LIMIT 1",$search_name));
|
| 701 |
}
|
| 702 |
|
| 703 |
|
| 704 |
function _semantic_search_set_search_field_vars($form_values){
|
| 705 |
$search_id = $form_values['search_id'];
|
| 706 |
$fid= isset($form_values['id'])?$form_values['id']:null;
|
| 707 |
$title = $form_values['title'];
|
| 708 |
$description = $form_values['description'];
|
| 709 |
$uris = $form_values['uris'];
|
| 710 |
$form_type = $form_values['form_type'];
|
| 711 |
$search_field_type = $form_values['search_field_type'];
|
| 712 |
$title_as_option = $form_values['title_as_option'];
|
| 713 |
$grand_total = $form_values['grand_total'];
|
| 714 |
$multiple = $form_values['multiple'];
|
| 715 |
|
| 716 |
if ($fid === null){
|
| 717 |
db_query("INSERT INTO {semantic_search_searches_fields}
|
| 718 |
(title, description, uris, form_type, search_field_type, title_as_option, grand_total, multiple, sid)
|
| 719 |
VALUES
|
| 720 |
('%s','%s','%s','%s','%s',%d,%d,%d,%d) ",
|
| 721 |
$title,$description,$uris,$form_type,$search_field_type, $title_as_option,$grand_total,$multiple,$search_id);
|
| 722 |
$message = t('Created field @a for search @b',array('@b'=>$title));
|
| 723 |
drupal_set_message('Semantic Search: '.$message);
|
| 724 |
watchdog('Semantic Search',$message);
|
| 725 |
return mysql_insert_id(); // not the drupal way, I know
|
| 726 |
} else {
|
| 727 |
//update
|
| 728 |
db_query("UPDATE {semantic_search_searches_fields} SET
|
| 729 |
title='%s', description='%s', uris='%s', form_type='%s', search_field_type='%s',title_as_option=%d,grand_total=%d,multiple=%d
|
| 730 |
WHERE id=%d ",
|
| 731 |
$title,$description,$uris,$form_type,$search_field_type, $title_as_option,$grand_total,$multiple,$fid);
|
| 732 |
$message = t('Updated field @a for search @b',array('@b'=>$title));
|
| 733 |
drupal_set_message('Semantic Search: '.$message);
|
| 734 |
watchdog('Semantic Search',$message);
|
| 735 |
return $fid;
|
| 736 |
}
|
| 737 |
}
|
| 738 |
|
| 739 |
function _semantic_search_get_search_field_vars($fid){
|
| 740 |
if ($fid === null) return array();
|
| 741 |
return db_fetch_array(db_query("SELECT * FROM {semantic_search_searches_fields} WHERE id=%d LIMIT 1",$fid));
|
| 742 |
}
|
| 743 |
|
| 744 |
function _semantic_search_get_all_search_field_vars($search_name){
|
| 745 |
$results = db_query("SELECT b.* FROM {semantic_search_searches} as a, {semantic_search_searches_fields} as b WHERE a.name='%s' AND a.id=b.sid",$search_name);
|
| 746 |
$return_array = array();
|
| 747 |
while( $result = db_fetch_array($results)){
|
| 748 |
$return_array[] = $result;
|
| 749 |
}
|
| 750 |
return $return_array;
|
| 751 |
}
|
| 752 |
|
| 753 |
function _semantic_search_set_search_form_vars(&$form_values, $op){
|
| 754 |
$search_name = $form_values['search_name'];
|
| 755 |
$search_store_type = $form_values['search_store_type'];
|
| 756 |
$search_type = $form_values['search_type'];
|
| 757 |
$search_path = $form_values['search_path'];
|
| 758 |
$search_title = $form_values['search_title'];
|
| 759 |
$search_description = $form_values['search_description'];
|
| 760 |
|
| 761 |
if ($op == 'Create'){
|
| 762 |
db_query("INSERT INTO {semantic_search_searches} (name, type, store_type, path, title, description) VALUES ('%s','%s','%s','%s','%s','%s') ",$search_name,$search_type,$search_store_type,$search_path,$search_title, $search_description);
|
| 763 |
$message = t('Created search @s',array('@s'=>$search_name));
|
| 764 |
drupal_set_message('Semantic Search: '.$message);
|
| 765 |
watchdog('Semantic Search',$message);
|
| 766 |
} else {
|
| 767 |
//update
|
| 768 |
$search_id = $form_values['search_id'];
|
| 769 |
//search name can not be changed
|
| 770 |
db_query("UPDATE {semantic_search_searches} SET type='%s', store_type='%s', path='%s', title='%s', description='%s' WHERE id=%d ",$search_type,$search_store_type,$search_path,$search_title, $search_description,$search_id);
|
| 771 |
$message = t('Updated search @s',array('@s'=>$search_name));
|
| 772 |
drupal_set_message('Semantic Search: '.$message);
|
| 773 |
watchdog('Semantic Search',$message);
|
| 774 |
}
|
| 775 |
|
| 776 |
// node_settings text utf8_unicode_ci No Browse distinct values Change Drop Primary Unique Index Fulltext
|
| 777 |
|
| 778 |
return $search_name;
|
| 779 |
}
|
| 780 |
|
| 781 |
|