123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * materiobase_search_autocomplete()
- *
- * inspired by taxonomy_autocomplete()
- *
- */
- function materiobase_search_autocomplete_dbselect($typed = ''){
- // If the request has a '/' in the search text, then the menu system will have
- // split it into multiple arguments, recover the intended $tags_typed.
- $args = func_get_args();
- $typed = implode('/', $args);
-
- /*
- TODO riche serach engine + \\ etc gmail like
- */
-
- if ($typed != '') {
- // Part of the criteria for the query come from the field's own settings.
- $vids = array();
- $vocabularies = taxonomy_vocabulary_get_names();
- foreach ($vocabularies as $voc) {
- $vids[] = $voc->vid;
- }
- $query = db_select('taxonomy_term_data', 't');
- $query->addTag('translatable');
- $query->addTag('term_access');
- // Select rows that match by term name.
- $tags_return = $query
- ->fields('t', array('tid', 'name'))
- ->condition('t.vid', $vids)
- ->condition('t.name', '%' . db_like($typed) . '%', 'LIKE')
- ->range(0, 10)
- ->execute()
- ->fetchAllKeyed();
- $term_matches = array();
- foreach ($tags_return as $tid => $name) {
- $n = $name;
- // Term names containing commas or quotes must be wrapped in quotes.
- // if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
- // $n = '"' . str_replace('"', '""', $name) . '"';
- // }
- $term_matches[$n] = check_plain($name);
- }
- }
- drupal_json_output($term_matches);
-
- }
- function materiobase_search_autocomplete_searchapi($typed = ''){
- // If the request has a '/' in the search text, then the menu system will have
- // split it into multiple arguments, recover the intended $tags_typed.
- $args = func_get_args();
- $typed = implode('/', $args);
-
- /*
- TODO riche serach engine + \\ etc gmail like
- */
-
- if ($typed != '') {
- $query = search_api_query('referencement');
- $query_filter = $query->createFilter();
- $query_filter->condition('name', $typed);
- // $query_filter->condition('type', 'article');
- $query->filter($query_filter);
- $tags_return = $query->execute();
-
- dsm($tags_return, '$tags_return');
- $term_matches = array();
- $index = search_api_index_load('referencement');
- foreach ($index->loadItems(array_keys($tags_return['results'])) as $item) {
- dsm($item, '$item');
- }
-
- //
- // foreach ($tags_return as $tid => $name) {
- // $n = $name;
- // // Term names containing commas or quotes must be wrapped in quotes.
- // // if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
- // // $n = '"' . str_replace('"', '""', $name) . '"';
- // // }
- // $term_matches[$n] = check_plain($name);
- // }
- }
- drupal_json_output($term_matches);
-
- }
|