Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:yhahn/searchlight
Browse files Browse the repository at this point in the history
  • Loading branch information
miccolis committed Sep 9, 2010
2 parents 0d37131 + a698c5f commit d3e5ac4
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 23 deletions.
2 changes: 1 addition & 1 deletion includes/SearchlightDatasource.inc
Expand Up @@ -46,7 +46,7 @@ class SearchlightDatasource {
views_include('view');
$this->view = new view;
$this->view->base_table = $this->base_table;
$this->view->api_version = 3.0-alpha1;
$this->view->api_version = '3.0-alpha1';
$this->view->new_display('default', 'Default', 'default');
$this->view->set_display('default');
return $this;
Expand Down
3 changes: 2 additions & 1 deletion includes/SearchlightEnvironment.inc
Expand Up @@ -66,8 +66,9 @@ class SearchlightEnvironment {
$this->plugins = array();

foreach ($this->getFacets() as $name => $facet) {
$field = isset($this->datasource->fields[$name]) ? $this->datasource->fields[$name] : array();
$plugin = searchlight_get_facet($this->datasource, $name);
$plugin->construct($this, $this->datasource->fields[$name], $this->getValue($name), $this->facets[$name]);
$plugin->construct($this, $field, $this->getValue($name), $this->facets[$name]);
$this->plugins[$name] = $plugin;
}
}
Expand Down
9 changes: 6 additions & 3 deletions plugins/SearchlightBackend.inc
Expand Up @@ -73,10 +73,13 @@ abstract class SearchlightBackend {
'#type' => 'textfield',
'#title' => t('Value'),
'#size' => 30,
'#default_value' => $this->value,
'#default_value' => $handler->value,
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
if (isset($handler->options['expose']['identifier'])) {
$identifier = $handler->options['expose']['identifier'];
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $handler->value;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/SearchlightBackendSolr.inc
Expand Up @@ -212,7 +212,9 @@ class SearchlightBackendSolr extends SearchlightBackend {
$date_facets = array();

foreach ($facets as $facet) {
$options["f.{$facet['field']}.facet.limit"] = $facet['limit'];
if (!empty($facet['limit'])) {
$options["f.{$facet['field']}.facet.limit"] = $facet['limit'];
}

$field = $datasource->fields[$facet['field']];
switch ($field['datatype']) {
Expand Down
75 changes: 70 additions & 5 deletions plugins/SearchlightBackendSphinx.inc
Expand Up @@ -15,6 +15,12 @@ class SearchlightBackendSphinx extends SearchlightBackend {
'port' => 9312,
'delta_ttl' => 0,
'sql_sock' => '',
'index' => array(
'morphology' => 'stem_en',
'charset_table' => NULL,
'ngram_len' => NULL,
'ngram_chars' => NULL,
),
);
}

Expand Down Expand Up @@ -43,6 +49,45 @@ class SearchlightBackendSphinx extends SearchlightBackend {
'#default_value' => $this->settings['delta_ttl'],
'#size' => 6,
);
$form['index'] = array(
'#type' => 'fieldset',
'#title' => t('Index settings'),
'#description' => t('Advanced configuration options for Sphinx. Use these options to enable CJK or other character set handling for Sphinx. Otherwise, you can leave these blank.')
);
$form['index']['morphology'] = array(
'#title' => t('Morphology'),
'#description' => t('Morphology processors to apply. See !link', array(
'!link' => l(t('Sphinx: morphology'), 'http://www.sphinxsearch.com/docs/current.html#conf-morphology')
)),
'#type' => 'textfield',
'#default_value' => $this->settings['index']['morphology'],
);
$form['index']['charset_table'] = array(
'#title' => t('Character set table'),
'#description' => t('Character set table. See !link and !charset for a variety of options', array(
'!link' => l(t('Sphinx: charset_table'), 'http://www.sphinxsearch.com/docs/current.html#conf-charset-table'),
'!charset' => l(t('Unicode character set tables'), 'http://sphinxsearch.com/wiki/doku.php?id=charset_tables'),
)),
'#type' => 'textfield',
'#default_value' => $this->settings['index']['charset_table'],
);
$form['index']['ngram_len'] = array(
'#title' => t('N-gram length'),
'#description' => t('Set n-gram length to 1 for basic CJK support. See !link', array(
'!link' => l(t('Sphinx: ngram_len'), 'http://www.sphinxsearch.com/docs/current.html#ngram_len'),
)),
'#type' => 'textfield',
'#default_value' => $this->settings['index']['ngram_len'],
);
$form['index']['ngram_chars'] = array(
'#title' => t('N-gram characters list'),
'#description' => t('N-gram characters list for basic CJK support. See !link and !charset for CJK support', array(
'!link' => l(t('Sphinx: ngram_chars'), 'http://www.sphinxsearch.com/docs/current.html#ngram_chars'),
'!charset' => l(t('CJK n-gram characters'), 'http://sphinxsearch.com/wiki/doku.php?id=charset_tables#cjk_ngram_characters')
)),
'#type' => 'textfield',
'#default_value' => $this->settings['index']['ngram_chars'],
);
return $form;
}

Expand Down Expand Up @@ -118,7 +163,9 @@ class SearchlightBackendSphinx extends SearchlightBackend {
}

// Set result limit.
$client->SetLimits(0, (int) $limit);
if (!empty($limit)) {
$client->SetLimits(0, (int) $limit);
}
$client->AddQuery($query, $this->sphinxGetIndex($datasource));
}

Expand Down Expand Up @@ -582,7 +629,7 @@ class SearchlightBackendSphinx extends SearchlightBackend {
}
}
}
return $client->SetFilter($attribute, $ordinals, $exclude);
return !empty($ordinals) ? $client->SetFilter($attribute, $ordinals, $exclude) : FALSE;
}

/**
Expand Down Expand Up @@ -618,15 +665,33 @@ class SearchlightBackendSphinx extends SearchlightBackend {
$conf['index']['path'] = $this->drushGetConfigPath() . '/indexes/' . $datasource_id;
$conf['index']['docinfo'] = 'extern';
$conf['index']['mlock'] = 0;
$conf['index']['morphology'] = 'stem_en';
$conf['index']['min_word_len'] = 1;

// Morphology settings.
if (!empty($this->settings['index']['morphology'])) {
$conf['index']['morphology'] = $this->settings['index']['morphology'];
}
// Charactsets, CJK handling, etc.
if (!empty($this->settings['index']['charset_table'])) {
$conf['index']['charset_table'] = $this->settings['index']['charset_table'];
}
if (!empty($this->settings['index']['ngram_len'])) {
$conf['index']['ngram_len'] = $this->settings['index']['ngram_len'];
}
if (!empty($this->settings['index']['ngram_chars'])) {
$conf['index']['ngram_chars'] = $this->settings['index']['ngram_chars'];
}

// Assume UTF-8, character stripping for now.
$conf['index']['charset_type'] = 'utf-8';
$conf['index']['html_strip'] = 0;

// Build the query.
$datasource->init();
$datasource->view->build();
if ($view = $datasource->view) {
// Force utf8 when indexing.
$conf['conf']['sql_query_pre'] = "SET NAMES utf8";

$sql_query = drupal_clone($view->query);
$sql_query->add_where(0, "{$view->base_table}.{$view->base_field}" .' BETWEEN $start AND $end');
$sql_query->add_field(NULL, '0', 'searchlight_deleted');
Expand Down Expand Up @@ -748,7 +813,7 @@ class SearchlightBackendSphinx extends SearchlightBackend {
}
}
if (is_numeric($value)) {
return array_search($value, $this->ordinals[$datasource_id][$attribute_name]);
return isset($this->ordinals[$datasource_id][$attribute_name]) ? array_search($value, $this->ordinals[$datasource_id][$attribute_name]) : FALSE;
}
else {
return isset($this->ordinals[$datasource_id][$attribute_name][$value]) ? $this->ordinals[$datasource_id][$attribute_name][$value] : FALSE;
Expand Down
2 changes: 1 addition & 1 deletion plugins/SearchlightFacet.inc
Expand Up @@ -232,7 +232,7 @@ class SearchlightFacet {
'#title' => t('Items to show'),
'#type' => 'select',
'#default_value' => $this->options['items'],
'#options' => drupal_map_assoc(range(1, 20)),
'#options' => drupal_map_assoc(range(1, 20)) + array(0 => t('Show all')),
);
}

Expand Down
63 changes: 63 additions & 0 deletions plugins/SearchlightFacetLanguage.inc
@@ -0,0 +1,63 @@
<?php

/**
* Facet plugin class for language.
*/
class SearchlightFacetLanguage extends SearchlightFacet {
/**
* Override of query().
* Merges null value filtering with the site default language.
*/
function query(&$query) {
// Filter the query if there is an active facet value.
if (isset($this->value)) {
$default = language_default('language');
if (empty($this->value) || $this->value === $default) {
$query->search_filter[] = array(
'field' => $this->name,
'operator' => 'IN',
'args' => array('', $default),
);
}
else {
$query->search_filter[] = array(
'field' => $this->name,
'operator' => '=',
'args' => array($this->value),
);
}
}

// Add this facet to be built by the backend.
$limit = isset($this->options['items']) ? $this->options['items'] : 5;
$query->add_search_facet($this->name, $limit);
}

/**
* Override of render().
* Merges null value facet with the site default language facet.
*/
function render($query, $delta) {
switch ($delta) {
case 'active':
if (isset($this->value)) {
$items = array($this->value => array('id' => $this->value));
}
break;
case 'facets':
if (!isset($this->value)) {
$items = $query->get_search_facet($this->name);
}
break;
}
if (!empty($items) && $this->viewInit($query)) {
$default = language_default('language');
if (isset($items[$default], $items[''])) {
$items[$default]['count'] = $items[$default]['count'] + $items['']['count'];
unset($items['']);
}
return $this->viewRenderItems($items);
}
return array();
}
}
14 changes: 14 additions & 0 deletions plugins/SearchlightFacetSearchQuery.inc
Expand Up @@ -5,6 +5,20 @@
* fulltext search query.
*/
class SearchlightFacetSearchQuery extends SearchlightFacet {
/**
* Override of construct().
*/
function construct($environment, $field, $value, $options) {
$this->name = 'search_query';
$this->field = $field;
$this->value = $value;
$this->options = $options + $this->optionsDefault();
$this->environment = $environment;

$this->view = NULL;
$this->handler = NULL;
}

/**
* Override of query().
*/
Expand Down
22 changes: 19 additions & 3 deletions searchlight.module
Expand Up @@ -430,6 +430,14 @@ function searchlight_searchlight_plugins() {
'parent' => 'SearchlightFacet',
),
),
'SearchlightFacetLanguage' => array(
'handler' => array(
'path' => drupal_get_path('module', 'searchlight') .'/plugins',
'file' => 'SearchlightFacetLanguage.inc',
'class' => 'SearchlightFacetLanguage',
'parent' => 'SearchlightFacet',
),
),
);
}

Expand Down Expand Up @@ -465,6 +473,10 @@ function searchlight_searchlight_registry() {
'title' => t('Date'),
'plugin' => 'SearchlightFacetDatatypeTimestamp',
),
'users_language' => array(
'title' => t('Language'),
'plugin' => 'SearchlightFacetLanguage',
),
),
);
}
Expand Down Expand Up @@ -573,14 +585,18 @@ function searchlight_get_backend($id = NULL, $reset = FALSE) {
*/
function searchlight_get_facet($datasource, $name) {
// Build array of suggestion plugin registry names.
$field = $datasource->fields[$name];
$suggestions = array();
$field = isset($datasource->fields[$name]) ? $datasource->fields[$name] : NULL;
// Allow facets to be defined by table/field.
$suggestions[] = "{$field['table']}_{$field['field']}";
if ($field) {
$suggestions[] = "{$field['table']}_{$field['field']}";
}
// Allow facets to be defined by alias.
$suggestions[] = $name;
// Allow facets to be defined by datatype.
$suggestions[] = "datatype_{$field['datatype']}";
if ($field) {
$suggestions[] = "datatype_{$field['datatype']}";
}
// Fallback to default plugin.
$suggestions[] = 'default';

Expand Down
2 changes: 1 addition & 1 deletion searchlight_basic/searchlight_basic.features.views.inc
Expand Up @@ -14,7 +14,7 @@ function _searchlight_basic_views_default_views() {
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 3.0-alpha1;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
Expand Down
2 changes: 2 additions & 0 deletions theme/searchlight-sphinx-index-conf.tpl.php
Expand Up @@ -14,6 +14,8 @@
sql_sock = <?php print $datasource['conf']['sql_sock'] ?>
<?php endif; ?>

sql_query_pre = \
<?php print $datasource['conf']['sql_query_pre'] ?>
sql_query = \
<?php print $datasource['conf']['sql_query'] ?>
sql_query_info = \
Expand Down

0 comments on commit d3e5ac4

Please sign in to comment.