Module: Litesearch::Model::ActiveRecordClassMethods
- Defined in:
- lib/litestack/litesearch/model.rb
Instance Method Summary collapse
- #create_instance(row) ⇒ Object
- #fetch_row(id) ⇒ Object
- #get_connection ⇒ Object
- #search(term) ⇒ Object
Instance Method Details
#create_instance(row) ⇒ Object
193 194 195 |
# File 'lib/litestack/litesearch/model.rb', line 193 def create_instance(row) instantiate(row) end |
#fetch_row(id) ⇒ Object
170 171 172 |
# File 'lib/litestack/litesearch/model.rb', line 170 def fetch_row(id) find(id) end |
#get_connection ⇒ Object
166 167 168 |
# File 'lib/litestack/litesearch/model.rb', line 166 def get_connection connection.raw_connection end |
#search(term) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/litestack/litesearch/model.rb', line 174 def search(term) if @schema_not_created get_connection.search_index(index_name) do |schema| schema.merge(@schema) schema.model_class = self if schema.respond_to? :model_class end @schema_not_created = false end self.select( "#{table_name}.*" ).joins( "INNER JOIN #{index_name} ON #{table_name}.id = #{index_name}.rowid AND rank != 0 AND #{index_name} MATCH ", Arel.sql("'#{term}'") ).select( "-#{index_name}.rank AS search_rank" ).order( Arel.sql("#{index_name}.rank") ) end |