Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:42:45+00:00 2026-06-17T19:42:45+00:00

I have a Rails application that is now set up with ElasticSearch and the

  • 0

I have a Rails application that is now set up with ElasticSearch and the Tire gem to do searching on a model and I was wondering how I should set up my application to do fuzzy string matching on certain indexes in the model. I have my model set up to index on things like title, description, etc. but I want to do fuzzy string matching on some of those and I’m not sure where to do this at. I will include my code below if you would like to comment! Thanks!

In the controller:

    def search
      @resource = Resource.search(params[:q], :page => (params[:page] || 1),
                                 :per_page =>15, load: true )
   end

In the Model:

class Resource < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  belongs_to :user
  has_many :resource_views, :class_name => 'UserResourceView'

  has_reputation :votes, source: :user, aggregated_by: :sum

  attr_accessible :title, :description, :link, :tag_list, :user_id, :youtubeID
  acts_as_taggable

  mapping do 
      indexes :id,  :index => :not_analyzed
      indexes :title, :analyzer => 'snowball', :boost => 40
      indexes :tag_list, :analyzer => 'snowball', :boost => 8
      indexes :description, :analyzer => 'snowball', :boost => 2
      indexes :user_id, :analyzer => 'snowball'
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:42:47+00:00Added an answer on June 17, 2026 at 7:42 pm

    Try creating custom analyzers to achieve other stemming features, etc.
    Check out my example (this example also uses Mongoid & attachments, don’t look at it if you don’t need it):

    class Document
          include Mongoid::Document
          include Mongoid::Timestamps
          include Tire::Model::Search
          include Tire::Model::Callbacks
    
          field :filename, type: String
          field :md5, type: String
          field :tags, type: String
          field :size, type: String
    
          index({md5: 1}, {unique: true})
          validates_uniqueness_of :md5
    
    
          DEFAULT_PAGE_SIZE = 10
    
          settings :analysis => {
              :filter => {
                  :ngram_filter => {
                      :type => "edgeNGram",
                      :min_gram => 2,
                      :max_gram => 12
                  },
                  :custom_word_delimiter => {
                      :type => "word_delimiter",
                      :preserve_original => "true",
                      :catenate_all => "true",
                  }
              }, :analyzer => {
                  :index_ngram_analyzer => {
                      :type => "custom",
                      :tokenizer => "standard",
                      :filter => ["lowercase", "ngram_filter", "asciifolding", "custom_word_delimiter"]
                  },
                  :search_ngram_analyzer => {
                      :type => "custom",
                      :tokenizer => "standard",
                      :filter => ["standard", "lowercase", "ngram_filter", "custom_word_delimiter"]
                  },
                  :suggestions => {
                      :tokenizer => "standard",
                      :filter => ["suggestions_shingle"]
                  }
              }
          } do
            mapping {
              indexes :id, index: :not_analyzed
              indexes :filename, :type => 'string', :store => 'yes', :boost => 100, :search_analyzer => :search_ngram_analyzer, :index_analyzer => :index_ngram_analyzer
              indexes :tags, :type => 'string', :store => 'yes', :search_analyzer => :search_ngram_analyzer, :index_analyzer => :index_ngram_analyzer
              indexes :attachment, :type => 'attachment',
                      :fields => {
                          :content_type => {:store => 'yes'},
                          :author => {:store => 'yes', :analyzer => 'keyword'},
                          :title => {:store => 'yes'},
                          :attachment => {:term_vector => 'with_positions_offsets', :boost => 90, :store => 'yes', :search_analyzer => :search_ngram_analyzer, :index_analyzer => :index_ngram_analyzer},
                          :date => {:store => 'yes'}
                      }
            }
          end
    
    
          def to_indexed_json
            self.to_json(:methods => [:attachment])
          end
    
          def attachment        
              path_to_file = "#{Rails.application.config.document_library}#{path}/#{filename}"
              Base64.encode64(open(path_to_file) { |file| file.read })
          end
    
          def self.search(query, options)
            tire.search do
              query { string "#{query}", :default_operator => :AND, :default_field => 'attachment', :fields => ['filename', 'attachment', 'tags'] }
              highlight :attachment
              page = (options[:page] || 1).to_i
              search_size = options[:per_page] || DEFAULT_PAGE_SIZE
              from (page -1) * search_size
              size search_size
              sort { by :_score, :desc }
              if (options[:facet])
                filter :terms, :tags => [options[:facet]]
                facet 'global-tags', :global => true do
                  terms :tags
                end
                facet 'current-tags' do
                  terms :tags
                end
              end
            end
          end
        end
    

    Hope it helps,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model in a Rails/Mongoid application that I had initially set a
I have a Rails application that right now is pretty standard: Heroku/PostgreSQL backend, users
We have a Rails application that is running in a MySQL master-slave set-up for
In my rails application I have a set of attachments that display, with a
I have set up a rails application that uses single table inheritance but I
I have a Rails application that accepts file uploads of CSV files. When developing
I have a rails application that about 3 years old, and I'm having a
I have a Rails application that uses ActiveRecordStore for sessions. I need a PHP
I have a Rails application that lists information about local services. My objectives for
I have a rails application that allows searches using longitude and latitude. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.