You are here

class FuzzysearchExcerpt in Fuzzy Search 7

Processor to set the index and search settings. Requires FuzzySearchService.

Hierarchy

Expanded class hierarchy of FuzzysearchExcerpt

1 string reference to 'FuzzysearchExcerpt'
fuzzysearch_search_api_processor_info in ./fuzzysearch.module
Implements hook_search_api_processor_info().

File

includes/processor_excerpt.inc, line 11
File for processor excerpt.

View source
class FuzzysearchExcerpt extends SearchApiAbstractProcessor {

  /**
   * {@inheritdoc}
   */
  public function supportsIndex(SearchApiIndex $index) {
    return $index
      ->server() && $index
      ->server()
      ->supportsFeature('fuzzysearch');
  }

  /**
   * {@inheritdoc}
   */
  public function configurationForm() {
    $form['debug_score'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display scoring'),
      '#description' => t('If selected, the completeness and score of the results will be shown below each result, which may be helpful for tuning the display.'),
      '#default_value' => FALSE,
    );
    $form['excerpt_length'] = array(
      '#type' => 'textfield',
      '#title' => t('Result excerpt length'),
      '#size' => 3,
      '#maxlength' => 3,
      '#description' => t('Set the length of the displayed text excerpt containing a found search term. Applies per found term.'),
      '#default_value' => 200,
    );
    $form['max_result_length'] = array(
      '#type' => 'textfield',
      '#title' => t('Maximum result length'),
      '#size' => 4,
      '#maxlength' => 4,
      '#description' => t('Set the maximum length of the displayed result. Set to 0 for unlimited length. Applies per result.'),
      '#default_value' => 400,
    );
    $form['spelling'] = array(
      '#type' => 'textfield',
      '#title' => t('Minimum spelling score'),
      '#size' => 3,
      '#maxlength' => 3,
      '#description' => t('Fuzzysearch tries to highlight search terms that may be misspelled. You can set the minimum threshold, which is calculated as a ratio of ngram hits to misses in a term. 0 may cause a misspelling to highlight everything, and 100 will only highlight exact terms. Enter value between 0 and 100. Changing this setting does not require reindexing.'),
      '#default_value' => 30,
    );
    if (!empty($this->options)) {
      $form['debug_score']['#default_value'] = $this->options['debug_score'];
      $form['excerpt_length']['#default_value'] = $this->options['excerpt_length'];
      $form['max_result_length']['#default_value'] = $this->options['max_result_length'];
      $form['spelling']['#default_value'] = $this->options['spelling'];
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function postprocessSearchResults(array &$response, SearchApiQuery $query) {
    $keys = $query
      ->getKeys();
    if (is_array($keys)) {
      foreach ($keys as $key => &$v) {
        if (!element_child($key)) {
          unset($keys[$key]);
        }
      }
    }
    if (!empty($response['results'])) {
      $entity_info = entity_get_info($this->index->item_type);

      // Better way to check if we have text?
      if (isset($entity_info['view modes']['full'])) {
        $entities = entity_load($this->index->item_type, array_keys($response['results']));
        foreach ($entities as $key => $entity) {
          $response['results'][$key]['excerpt'] = fuzzysearch_build_excerpt($entity, $this->index, (array) $keys);
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FuzzysearchExcerpt::configurationForm public function Display a form for configuring this processor. Since forcing users to specify options for disabled processors makes no sense, none of the form elements should have the '#required' attribute set. Overrides SearchApiAbstractProcessor::configurationForm
FuzzysearchExcerpt::postprocessSearchResults public function Does nothing. Overrides SearchApiAbstractProcessor::postprocessSearchResults
FuzzysearchExcerpt::supportsIndex public function Check whether this processor is applicable for a certain index. Overrides SearchApiAbstractProcessor::supportsIndex
SearchApiAbstractProcessor::$index protected property
SearchApiAbstractProcessor::$options protected property
SearchApiAbstractProcessor::configurationFormSubmit public function Submit callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface::configurationFormSubmit
SearchApiAbstractProcessor::configurationFormValidate public function Validation callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface::configurationFormValidate 4
SearchApiAbstractProcessor::implodeTokens protected function Internal helper function for imploding tokens into a single string.
SearchApiAbstractProcessor::normalizeTokens protected function Internal helper function for normalizing tokens.
SearchApiAbstractProcessor::preprocessIndexItems public function Calls processField() for all appropriate fields. Overrides SearchApiProcessorInterface::preprocessIndexItems
SearchApiAbstractProcessor::preprocessSearchQuery public function Calls processKeys() for the keys and processFilters() for the filters. Overrides SearchApiProcessorInterface::preprocessSearchQuery 1
SearchApiAbstractProcessor::process protected function Function that is ultimately called for all text by the standard implementation, and does nothing by default. 5
SearchApiAbstractProcessor::processField protected function Method for preprocessing field data.
SearchApiAbstractProcessor::processFieldValue protected function Called for processing a single text element in a field. The default implementation just calls process(). 2
SearchApiAbstractProcessor::processFilters protected function Method for preprocessing query filters.
SearchApiAbstractProcessor::processFilterValue protected function Called for processing a single filter value. The default implementation just calls process().
SearchApiAbstractProcessor::processKey protected function Called for processing a single search keyword. The default implementation just calls process().
SearchApiAbstractProcessor::processKeys protected function Method for preprocessing search keys.
SearchApiAbstractProcessor::testField protected function Determines whether to process data from the given field.
SearchApiAbstractProcessor::testType protected function Determines whether fields of the given type should normally be processed.
SearchApiAbstractProcessor::__construct public function Constructor, saving its arguments into properties. Overrides SearchApiProcessorInterface::__construct 2