Skip to content

Instantly share code, notes, and snippets.

@cedricdekimpe
Created October 24, 2013 09:06
Show Gist options
  • Save cedricdekimpe/7133767 to your computer and use it in GitHub Desktop.
Save cedricdekimpe/7133767 to your computer and use it in GitHub Desktop.
LocomotiveCMS search : config/initializer/add_full_text_to_locomotive.rb
#encoding: utf-8
::STOP_WORDS = Hash[[
"alors", "au", "aucuns", "aussi", "autre", "avant", "avec", "avoir",
"bon", "car", "ce", "cela", "ces", "ceux", "chaque", "ci", "comme", "comment", "dans", "des", "du",
"dedans", "dehors", "depuis", "deux", "devrait", "doit", "donc", "dos", "droite", "début", "elle",
"elles", "en", "encore", "essai", "est", "et", "eu", "fait", "faites", "fois", "font",
"force", "haut", "hors", "ici", "il", "ils", "je juste", "la", "le", "les", "leur", "là", "ma", "maintenant",
"mais", "mes", "mine", "moins", "mon", "mot", "même", "ni", "nommés", "notre", "nous", "nouveaux", "ou", "où",
"par", "parce", "parole", "pas", "personnes", "peut", "peu", "pièce", "plupart", "pour", "pourquoi", "quand", "que",
"quel", "quelle", "quelles", "quels", "qui", "sa", "sans", "ses", "seulement", "si", "sien", "son", "sont", "sous",
"soyez", "sujet", "sur", "ta", "tandis", "tellement", "tels", "tes", "ton", "tous", "tout", "trop", "très", "tu",
"valeur", "voie", "voient", "vont", "votre", "vous", "vu", "ça", "étaient", "état", "étions", "été", "être", 'i',
'a', 's', 't', 'me', 'my', 'we', 'he', 'it', 'am', 'is', 'be', 'do', 'an', 'if',
'or', 'as', 'of', 'at', 'by', 'to', 'up', 'in', 'on', 'no', 'so', 'our', 'you', 'him',
'his', 'she', 'her', 'its', 'who', 'are', 'was', 'has', 'had', 'did', 'the', 'and',
'but', 'for', 'out', 'off', 'why', 'how', 'all', 'any', 'few', 'nor', 'not', 'own',
'too', 'can', 'don', 'now', 'ours', 'your', 'hers', 'they', 'them', 'what', 'whom',
'this', 'that', 'were', 'been', 'have', 'does', 'with', 'into', 'from', 'down', 'over',
'then', 'once', 'here', 'when', 'both', 'each', 'more', 'most', 'some', 'such', 'only',
'same', 'than', 'very', 'will', 'just', 'yours', 'their', 'which', 'these', 'those',
'being', 'doing', 'until', 'while', 'about', 'after', 'above', 'below', 'under',
'again', 'there', 'where', 'other', 'myself', 'itself', 'theirs', 'having', 'during',
'before', 'should', 'himself', 'herself', 'because', 'against', 'between', 'through',
'further', 'yourself', 'ourselves', 'yourselves', 'themselves'
].map{ |x| [x,true] }]
Locomotive::ContentEntry.class_eval do
include Mongoid::FullTextSearch
fulltext_search_in :post_content, :post_summary, :post_title, :stop_words => ::STOP_WORDS, :max_ngrams_to_search => 1
def post_content
self.content if self.respond_to?(:content)
end
def post_summary
self.summary if self.respond_to?(:summary)
end
def post_title
self.title if self.respond_to?(:title)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment