module SearchHelper

OpenIrekia v4.0.0

Copyright 2009-2013 eFaber, S.L. Copyright 2009-2013 Ejie, S.A. Copyrigth 2009-2013 Dirección de Gobierno Abierto y Comunicación en Internet;

Gobernu Irekirako eta Interneteko Komunikaziorako Zuzendaritza; Lehendakaritza.
Gobierno Vasco – Eusko Jaurlaritza

Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto sean aprobadas por la Comisión Europea– versiones posteriores de la EUPL (la Licencia); Solo podrá usarse esta obra si se respeta la Licencia. Puede obtenerse una copia de la Licencia en: ec.europa.eu/idabc/eupl Salvo cuando lo exija la legislación aplicable o se acuerde por escrito, el programa distribuido con arreglo a la Licencia se distribuye TAL CUAL, SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas. Véase la Licencia en el idioma concreto que rige los permisos y limitaciones que establece la Licencia

http://open.irekia.net, openirekia@efaber.net

Public Instance Methods

facet_in_current_locale(facet) click to toggle source
# File app/helpers/search_helper.rb, line 93
def facet_in_current_locale(facet)
  position = {'en' => 0, 'es' => 1, 'eu' => 2}
  value=facet.split('|')[position[I18n.locale.to_s]]
  unless value.present?
    value=facet.split('|')[0]
  end  
  value
end
get_highlight_regexp(keyword) click to toggle source
# File app/helpers/search_helper.rb, line 112
def get_highlight_regexp(keyword)
  keyword.present? ? Regexp.new(/(#{keyword.escape_for_elasticsearch(true).gsub(/\*/, '').split(' ').join('|')})s?[\s|\.|,|\<\"]/x) : nil
end
highlight_according_to_criterio(text, criterio) click to toggle source
# File app/helpers/search_helper.rb, line 102
def highlight_according_to_criterio(text, criterio)
  unless criterio.nil? || criterio.only_title || criterio.title.match(/keyword/).nil?                           
    keyword = criterio.get_keywords
    output = highlight_according_to_regexp(text, get_highlight_regexp(keyword))
  else
    output = text        
  end          
  output
end
highlight_according_to_regexp(text, reg_exp) click to toggle source
# File app/helpers/search_helper.rb, line 116
def highlight_according_to_regexp(text, reg_exp)    
  reg_exp.present? ? text.gsub(reg_exp){|m| "<span class='highlight'>#{m.strip}</span> "} : text
end
show_criterio_title(criterio, complete=false) click to toggle source
# File app/helpers/search_helper.rb, line 24
def show_criterio_title(criterio, complete=false)
  output=criterio.title
  if criterio.parent && !complete
    output = output.gsub(criterio.parent.title, '')
  end
  aux=[]     
  output.split(' AND ').each do |part|
    values=part.split(': ')      
    values[1]=values[1..-1].join(': ') if values.size > 2
    case values[0]
    when *Elasticsearch::Base::TRANSLATABLE_FACETS
      value=facet_in_current_locale(values[1])
    when 'type'                                                 
      # value = Object.const_defined?(values[1].classify) ? values[1].classify.constantize.human_name(:count => 2) : nil        
      begin
        value = t("#{values[1]}.title")
      rescue
        value = nil
      end     
    when 'date'  
      value=I18n.t("search.date#{values[1]}")
    else
      value=values[1]  
    end          
    if values[0].present? 
      if values[0].eql?('keyword')
        aux << value
      else
        aux << "#{I18n.t("search.facets.#{values[0]}")}: #{value}" 
      end    
    end  
  end
  if aux.present?
    h(aux.to_sentence)
  else
    I18n.t('search.todos_los_contenidos')
  end  
end
show_score(item) click to toggle source
# File app/helpers/search_helper.rb, line 131
def show_score(item)
  if logged_in? && current_user.is_admin? && item.score.present?
    content_tag(:span, item.score, :class => 'score')
  end    
end
show_search_explanation(item) click to toggle source
# File app/helpers/search_helper.rb, line 120
def show_search_explanation(item)  
  if logged_in? && current_user.is_admin? && item.explanation.present?
    inner = content_tag(:div, link_to("<span>EXPL #{item.score}</span>", '#', :class => 'explanation_link'))
    block = content_tag(:div, link_to_function('Cerrar', "$('div#overlay').hide()"), :class => 'close')
    block << content_tag(:div, "SCORE: #{item.score}", :class => 'score')
    block << content_tag(:div, content_tag(:pre, JSON.pretty_generate(item.explanation)))
    inner << content_tag(:div, block, :class => 'explanation_content', :style => 'display: none')
    content_tag(:div, inner, :class => 'explanation_link')    
  end  
end