source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | bkeepers/dotenv | https://github.com/bkeepers/dotenv | lib/dotenv/diff.rb | Ruby | mit | 6,741 | main | 1,801 | module Dotenv
# A diff between multiple states of ENV.
class Diff
# The initial state
attr_reader :a
# The final or current state
attr_reader :b
# Create a new diff. If given a block, the state of ENV after the block will be preserved as
# the final state for comparison. Otherwise, the cur... |
github | bkeepers/dotenv | https://github.com/bkeepers/dotenv | lib/dotenv/substitutions/command.rb | Ruby | mit | 6,741 | main | 1,298 | require "English"
module Dotenv
module Substitutions
# Substitute shell commands in a value.
#
# SHA=$(git rev-parse HEAD)
#
module Command
class << self
INTERPOLATED_SHELL_COMMAND = /
(?<backslash>\\)? # is it escaped with a backslash?
\$ # ... |
github | bkeepers/dotenv | https://github.com/bkeepers/dotenv | lib/dotenv/substitutions/variable.rb | Ruby | mit | 6,741 | main | 884 | require "English"
module Dotenv
module Substitutions
# Substitute variables in a value.
#
# HOST=example.com
# URL="https://$HOST"
#
module Variable
class << self
VARIABLE = /
(\\)? # is it escaped with a backslash?
(\$) # literal $
... |
github | bkeepers/dotenv | https://github.com/bkeepers/dotenv | benchmark/parse_profile.rb | Ruby | mit | 6,741 | main | 464 | require "bundler/setup"
require "dotenv"
require "stackprof"
require "benchmark/ips"
require "tempfile"
f = Tempfile.create("benchmark_ips.env")
1000.times.map { |i| f.puts "VAR_#{i}=#{i}" }
f.close
profile = StackProf.run(mode: :wall, interval: 1_000) do
10_000.times do
Dotenv.parse(f.path, overwrite: false)
... |
github | bkeepers/dotenv | https://github.com/bkeepers/dotenv | benchmark/parse_ips.rb | Ruby | mit | 6,741 | main | 385 | require "bundler/setup"
require "dotenv"
require "benchmark/ips"
require "tempfile"
f = Tempfile.create("benchmark_ips.env")
1000.times.map { |i| f.puts "VAR_#{i}=#{i}" }
f.close
Benchmark.ips do |x|
x.report("parse, overwrite:false") { Dotenv.parse(f.path, overwrite: false) }
x.report("parse, overwrite:true") { ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | searchkick.gemspec | Ruby | mit | 6,709 | master | 601 | require_relative "lib/searchkick/version"
Gem::Specification.new do |spec|
spec.name = "searchkick"
spec.version = Searchkick::VERSION
spec.summary = "Intelligent search made easy with Rails and Elasticsearch or OpenSearch"
spec.homepage = "https://github.com/ankane/searchkick"
spec... |
github | ankane/searchkick | https://github.com/ankane/searchkick | Gemfile | Ruby | mit | 6,709 | master | 430 | source "https://rubygems.org"
gemspec
gem "rake"
gem "minitest"
gem "sqlite3", platform: :ruby
gem "sqlite3-ffi", platform: :jruby
gem "activerecord", "~> 8.1.0"
gem "actionpack", "~> 8.1.0"
gem "activejob", "~> 8.1.0", require: "active_job"
gem "elasticsearch", "~> 9"
gem "redis-client"
gem "connection_pool"
gem "ka... |
github | ankane/searchkick | https://github.com/ankane/searchkick | Rakefile | Ruby | mit | 6,709 | master | 235 | require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |t|
t.pattern = "test/**/*_test.rb"
end
task default: :test
# to test in parallel, uncomment and run:
# rake parallel:test
# require "parallel_tests/tasks" |
github | ankane/searchkick | https://github.com/ankane/searchkick | benchmark/relation.rb | Ruby | mit | 6,709 | master | 366 | require "bundler/setup"
Bundler.require(:default)
require "active_record"
class Product < ActiveRecord::Base
searchkick
end
Product.all # initial Active Record allocations
stats = AllocationStats.trace do
Product.search("apples").where(store_id: 1).where(in_stock: true).order(:name).limit(10).offset(50)
end
puts... |
github | ankane/searchkick | https://github.com/ankane/searchkick | benchmark/Gemfile | Ruby | mit | 6,709 | master | 384 | source "https://rubygems.org"
gemspec path: "../"
gem "sqlite3"
gem "pg"
gem "activerecord", "~> 8.0.0"
gem "activejob"
gem "elasticsearch"
# gem "opensearch-ruby"
gem "redis"
gem "sidekiq"
# performance
gem "typhoeus"
gem "oj"
gem "json"
# profiling
gem "ruby-prof"
gem "allocation_stats"
gem "get_process_mem"
gem ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | benchmark/search.rb | Ruby | mit | 6,709 | master | 1,106 | require "bundler/setup"
Bundler.require(:default)
require "active_record"
require "benchmark/ips"
ActiveRecord.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "/tmp/searchkick"
class Product < ActiveRecord::Base
searc... |
github | ankane/searchkick | https://github.com/ankane/searchkick | benchmark/index.rb | Ruby | mit | 6,709 | master | 2,632 | require "bundler/setup"
Bundler.require(:default)
require "active_record"
require "active_job"
require "benchmark"
require "active_support/notifications"
ActiveSupport::Notifications.subscribe "request.searchkick" do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
# puts "Import: #{event.duration.ro... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick.rb | Ruby | mit | 6,709 | master | 11,137 | # dependencies
require "active_support"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/module/attr_internal"
require "active_support/core_ext/module/delegation"
require "active_support/deprecation"
require "active_support/log_subscriber"
require "active_support/notifications"
# stdl... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/tasks/searchkick.rake | Ruby | mit | 6,709 | master | 980 | namespace :searchkick do
desc "reindex a model (specify CLASS)"
task reindex: :environment do
class_name = ENV["CLASS"]
abort "USAGE: rake searchkick:reindex CLASS=Product" unless class_name
model =
begin
Searchkick.load_model(class_name)
rescue Searchkick::Error => e
abort ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/reranking.rb | Ruby | mit | 6,709 | master | 637 | module Searchkick
module Reranking
def self.rrf(first_ranking, *rankings, k: 60)
rankings.unshift(first_ranking)
rankings.map!(&:to_ary)
ranks = []
results = []
rankings.each do |ranking|
ranks << ranking.map.with_index.to_h { |v, i| [v, i + 1] }
results.concat(ranki... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/index.rb | Ruby | mit | 6,709 | master | 14,153 | module Searchkick
class Index
attr_reader :name, :options
def initialize(name, options = {})
@name = name
@options = options
@klass_document_type = {} # cache
end
def index_options
IndexOptions.new(self).index_options
end
def create(body = {})
client.indices.cr... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/process_queue_job.rb | Ruby | mit | 6,709 | master | 1,127 | module Searchkick
class ProcessQueueJob < Searchkick.parent_job.constantize
queue_as { Searchkick.queue_name }
def perform(class_name:, index_name: nil, inline: false, job_options: nil)
model = Searchkick.load_model(class_name)
index = model.searchkick_index(name: index_name)
limit = model.... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/indexer.rb | Ruby | mit | 6,709 | master | 1,190 | # thread-local (technically fiber-local) indexer
# used to aggregate bulk callbacks across models
module Searchkick
class Indexer
attr_reader :queued_items
def initialize
@queued_items = []
end
def queue(items)
@queued_items.concat(items)
perform unless Searchkick.callbacks_value =... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/results.rb | Ruby | mit | 6,709 | master | 9,617 | module Searchkick
class Results
include Enumerable
extend Forwardable
attr_reader :response
def_delegators :results, :each, :any?, :empty?, :size, :length, :slice, :[], :to_ary
def initialize(klass, response, options = {})
@klass = klass
@response = response
@options = options... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/record_indexer.rb | Ruby | mit | 6,709 | master | 5,150 | module Searchkick
class RecordIndexer
attr_reader :index
def initialize(index)
@index = index
end
def reindex(records, mode:, method_name:, ignore_missing:, full: false, single: false, job_options: nil)
# prevents exists? check if records is a relation
records = records.to_a
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/process_batch_job.rb | Ruby | mit | 6,709 | master | 633 | module Searchkick
class ProcessBatchJob < Searchkick.parent_job.constantize
queue_as { Searchkick.queue_name }
def perform(class_name:, record_ids:, index_name: nil)
model = Searchkick.load_model(class_name)
index = model.searchkick_index(name: index_name)
items =
record_ids.map do... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/script.rb | Ruby | mit | 6,709 | master | 214 | module Searchkick
class Script
attr_reader :source, :lang, :params
def initialize(source, lang: "painless", params: {})
@source = source
@lang = lang
@params = params
end
end
end |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/hash_wrapper.rb | Ruby | mit | 6,709 | master | 797 | module Searchkick
class HashWrapper
def initialize(attributes)
@attributes = attributes
end
def [](name)
@attributes[name.to_s]
end
def to_h
@attributes
end
def as_json(...)
@attributes.as_json(...)
end
def to_json(...)
@attributes.to_json(...)
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/model.rb | Ruby | mit | 6,709 | master | 5,442 | module Searchkick
module Model
def searchkick(**options)
options = Searchkick.model_options.deep_merge(options)
if options[:conversions]
Searchkick.warn("The `conversions` option is deprecated in favor of `conversions_v2`, which provides much better search performance. Upgrade to `conversions... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/reindex_v2_job.rb | Ruby | mit | 6,709 | master | 798 | module Searchkick
class ReindexV2Job < Searchkick.parent_job.constantize
queue_as { Searchkick.queue_name }
def perform(class_name, id, method_name = nil, routing: nil, index_name: nil, ignore_missing: nil)
model = Searchkick.load_model(class_name, allow_child: true)
index = model.searchkick_inde... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/bulk_reindex_job.rb | Ruby | mit | 6,709 | master | 810 | module Searchkick
class BulkReindexJob < Searchkick.parent_job.constantize
queue_as { Searchkick.queue_name }
def perform(class_name:, record_ids: nil, index_name: nil, method_name: nil, batch_id: nil, min_id: nil, max_id: nil, ignore_missing: nil)
model = Searchkick.load_model(class_name)
index ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/log_subscriber.rb | Ruby | mit | 6,709 | master | 1,706 | # based on https://gist.github.com/mnutt/566725
module Searchkick
class LogSubscriber < ActiveSupport::LogSubscriber
def self.runtime=(value)
Thread.current[:searchkick_runtime] = value
end
def self.runtime
Thread.current[:searchkick_runtime] ||= 0
end
def self.reset_runtime
rt... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/query.rb | Ruby | mit | 6,709 | master | 45,443 | module Searchkick
class Query
include Enumerable
extend Forwardable
@@metric_aggs = [:avg, :cardinality, :max, :min, :sum]
attr_reader :klass, :term, :options
attr_accessor :body
def_delegators :execute, :map, :each, :any?, :empty?, :size, :length, :slice, :[], :to_ary,
:results, :sug... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/middleware.rb | Ruby | mit | 6,709 | master | 611 | require "faraday"
module Searchkick
class Middleware < Faraday::Middleware
def call(env)
path = env[:url].path.to_s
if path.end_with?("/_search")
env[:request][:timeout] = Searchkick.search_timeout
elsif path.end_with?("/_msearch")
# assume no concurrent searches for timeout for... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/controller_runtime.rb | Ruby | mit | 6,709 | master | 1,240 | # based on https://gist.github.com/mnutt/566725
module Searchkick
module ControllerRuntime
extend ActiveSupport::Concern
protected
attr_internal :searchkick_runtime
def process_action(action, *args)
# We also need to reset the runtime before each action
# because of queries in middlewar... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/relation.rb | Ruby | mit | 6,709 | master | 13,910 | module Searchkick
class Relation
NO_DEFAULT_VALUE = Object.new
# note: modifying body directly is not supported
# and has no impact on query after being executed
# TODO freeze body object?
delegate :params, to: :query
delegate_missing_to :private_execute
attr_reader :model
alias_meth... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/relation_indexer.rb | Ruby | mit | 6,709 | master | 5,840 | module Searchkick
class RelationIndexer
attr_reader :index
def initialize(index)
@index = index
end
def reindex(relation, mode:, method_name: nil, ignore_missing: nil, full: false, resume: false, scope: nil, job_options: nil)
# apply scopes
if scope
relation = relation.send... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/multi_search.rb | Ruby | mit | 6,709 | master | 1,089 | module Searchkick
class MultiSearch
attr_reader :queries
def initialize(queries, opaque_id: nil)
@queries = queries
@opaque_id = opaque_id
end
def perform
if queries.any?
perform_search(queries)
end
end
private
def perform_search(search_queries, perform_... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/record_data.rb | Ruby | mit | 6,709 | master | 3,771 | module Searchkick
class RecordData
TYPE_KEYS = ["type", :type]
attr_reader :index, :record
def initialize(index, record)
@index = index
@record = record
end
def index_data
data = record_data
data[:data] = search_data
{index: data}
end
def update_data(metho... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/index_cache.rb | Ruby | mit | 6,709 | master | 609 | module Searchkick
class IndexCache
def initialize(max_size: 20)
@data = {}
@mutex = Mutex.new
@max_size = max_size
end
# probably a better pattern for this
# but keep it simple
def fetch(name)
# thread-safe in MRI without mutex
# due to how context switching works
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/index_options.rb | Ruby | mit | 6,709 | master | 21,686 | module Searchkick
class IndexOptions
attr_reader :options
def initialize(index)
@options = index.options
end
def index_options
# mortal symbols are garbage collected in Ruby 2.2+
custom_settings = (options[:settings] || {}).deep_symbolize_keys
custom_mappings = (options[:mapp... |
github | ankane/searchkick | https://github.com/ankane/searchkick | lib/searchkick/reindex_queue.rb | Ruby | mit | 6,709 | master | 1,289 | module Searchkick
class ReindexQueue
attr_reader :name
def initialize(name)
@name = name
raise Error, "Searchkick.redis not set" unless Searchkick.redis
end
# supports single and multiple ids
def push(record_ids)
Searchkick.with_redis { |r| r.call("LPUSH", redis_key, record_id... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/partial_reindex_test.rb | Ruby | mit | 6,709 | master | 4,836 | require_relative "test_helper"
class PartialReindexTest < Minitest::Test
def test_record_inline
store [{name: "Hi", color: "Blue"}]
product = Product.first
Searchkick.callbacks(false) do
product.update!(name: "Bye", color: "Red")
end
product.reindex(:search_name, refresh: true)
# nam... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/inheritance_test.rb | Ruby | mit | 6,709 | master | 4,663 | require_relative "test_helper"
class InheritanceTest < Minitest::Test
def setup
super
setup_animal
end
def test_child_reindex
store_names ["Max"], Cat
assert Dog.reindex
assert_equal 1, Animal.search("*").size
end
def test_child_index_name
assert_equal "animals_test#{ENV["TEST_ENV_N... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/marshal_test.rb | Ruby | mit | 6,709 | master | 340 | require_relative "test_helper"
class MarshalTest < Minitest::Test
def test_marshal
store_names ["Product A"]
assert Marshal.dump(Product.search("*").to_a)
end
def test_marshal_highlights
store_names ["Product A"]
assert Marshal.dump(Product.search("product", highlight: true, load: {dumpable: tru... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/test_helper.rb | Ruby | mit | 6,709 | master | 1,334 | require "bundler/setup"
Bundler.require(:default)
require "minitest/autorun"
require "active_support/notifications"
ENV["RACK_ENV"] = "test"
# for reloadable synonyms
if ENV["CI"]
ENV["ES_PATH"] ||= File.join(ENV["HOME"], Searchkick.opensearch? ? "opensearch" : "elasticsearch", Searchkick.server_version)
end
$logg... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/notifications_test.rb | Ruby | mit | 6,709 | master | 644 | require_relative "test_helper"
class NotificationsTest < Minitest::Test
def test_search
Product.searchkick_index.refresh
notifications = capture_notifications do
Product.search("product").to_a
end
assert_equal 1, notifications.size
assert_equal "search.searchkick", notifications.last[:nam... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/boost_test.rb | Ruby | mit | 6,709 | master | 6,557 | require_relative "test_helper"
class BoostTest < Minitest::Test
# global boost
def test_boost
store [
{name: "Tomato A"},
{name: "Tomato B", orders_count: 10},
{name: "Tomato C", orders_count: 100}
]
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost: "orders_count"
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/conversions_test.rb | Ruby | mit | 6,709 | master | 8,775 | require_relative "test_helper"
class ConversionsTest < Minitest::Test
def setup
super
setup_speaker
end
def test_v1
store [
{name: "Tomato A", conversions: {"tomato" => 1}},
{name: "Tomato B", conversions: {"tomato" => 2}},
{name: "Tomato C", conversions: {"tomato" => 3}}
]
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/where_test.rb | Ruby | mit | 6,709 | master | 18,815 | require_relative "test_helper"
class WhereTest < Minitest::Test
def test_where
now = Time.now
store [
{name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]},
{name: "Product B", store_id: 2, in_stock: true, backordered: false, cr... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/should_index_test.rb | Ruby | mit | 6,709 | master | 1,013 | require_relative "test_helper"
class ShouldIndexTest < Minitest::Test
def test_basic
store_names ["INDEX", "DO NOT INDEX"]
assert_search "index", ["INDEX"]
end
def test_default_true
assert Store.new.should_index?
end
def test_change_to_true
store_names ["DO NOT INDEX"]
assert_search "in... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/similar_test.rb | Ruby | mit | 6,709 | master | 1,712 | require_relative "test_helper"
class SimilarTest < Minitest::Test
def test_similar
store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true, fields: [:name]
end
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/multi_tenancy_test.rb | Ruby | mit | 6,709 | master | 605 | require_relative "test_helper"
class MultiTenancyTest < Minitest::Test
def setup
skip unless defined?(Apartment)
end
def test_basic
Apartment::Tenant.switch!("tenant1")
store_names ["Product A"]
Apartment::Tenant.switch!("tenant2")
store_names ["Product B"]
Apartment::Tenant.switch!("ten... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/partial_match_test.rb | Ruby | mit | 6,709 | master | 2,884 | require_relative "test_helper"
class PartialMatchTest < Minitest::Test
def test_autocomplete
store_names ["Hummus"]
assert_search "hum", ["Hummus"], match: :text_start
end
def test_autocomplete_two_words
store_names ["Organic Hummus"]
assert_search "hum", [], match: :text_start
end
def test... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/aggs_test.rb | Ruby | mit | 6,709 | master | 14,911 | require_relative "test_helper"
class AggsTest < Minitest::Test
def setup
super
store [
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
{name: "Product Hide", latitude: 29.4167, longitude: -98.5000, store... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/scroll_test.rb | Ruby | mit | 6,709 | master | 2,864 | require_relative "test_helper"
class ScrollTest < Minitest::Test
def test_works
store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
products = Product.search("product", order: {name: :asc}, scroll: '1m', per_page: 2)
assert_equal ["Product A", "Product B"], products... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/default_scope_test.rb | Ruby | mit | 6,709 | master | 590 | require_relative "test_helper"
class DefaultScopeTest < Minitest::Test
def setup
setup_model(Band)
end
def test_reindex
store [
{name: "Test", active: true},
{name: "Test 2", active: false}
], reindex: false
Band.reindex
assert_search "*", ["Test"], {load: false}
end
def te... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/relation_test.rb | Ruby | mit | 6,709 | master | 3,707 | require_relative "test_helper"
class RelationTest < Minitest::Test
def test_loaded
Product.searchkick_index.refresh
products = Product.search("*")
refute products.loaded?
assert_equal 0, products.count
assert products.loaded?
refute products.clone.loaded?
refute products.dup.loaded?
r... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/suggest_test.rb | Ruby | mit | 6,709 | master | 3,105 | require_relative "test_helper"
class SuggestTest < Minitest::Test
def setup
super
Product.reindex
end
def test_basic
store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"]
assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name]
end
def test_perfec... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/pagination_test.rb | Ruby | mit | 6,709 | master | 8,741 | require_relative "test_helper"
class PaginationTest < Minitest::Test
def test_limit
store_names ["Product A", "Product B", "Product C", "Product D"]
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
assert_order_relation ["Product A", "Product B"], Product.search("product"... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/multi_indices_test.rb | Ruby | mit | 6,709 | master | 2,285 | require_relative "test_helper"
class MultiIndicesTest < Minitest::Test
def setup
super
setup_speaker
end
def test_basic
store_names ["Product A"]
store_names ["Product B"], Speaker
assert_search_multi "product", ["Product A", "Product B"]
end
def test_index_name
store_names ["Produc... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/hybrid_test.rb | Ruby | mit | 6,709 | master | 1,160 | require_relative "test_helper"
class HybridTest < Minitest::Test
def setup
skip unless Searchkick.knn_support?
super
end
def test_search
error = assert_raises(ArgumentError) do
Product.search("product", knn: {field: :embedding, vector: [1, 2, 3]})
end
assert_equal "Use Searchkick.multi... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/reindex_v2_job_test.rb | Ruby | mit | 6,709 | master | 715 | require_relative "test_helper"
class ReindexV2JobTest < Minitest::Test
def test_create
product = Searchkick.callbacks(false) { Product.create!(name: "Boom") }
Product.searchkick_index.refresh
assert_search "*", []
Searchkick::ReindexV2Job.perform_now("Product", product.id.to_s)
Product.searchkick... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/synonyms_test.rb | Ruby | mit | 6,709 | master | 1,213 | require_relative "test_helper"
class SynonymsTest < Minitest::Test
def test_bleach
store_names ["Clorox Bleach", "Kroger Bleach"]
assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"]
end
def test_burger_buns
store_names ["Hamburger Buns"]
assert_search "burger buns", ["Hamburger Buns"]
e... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/load_test.rb | Ruby | mit | 6,709 | master | 3,180 | require_relative "test_helper"
class LoadTest < Minitest::Test
def test_default
store_names ["Product A"]
product = Product.search("product").first
assert_kind_of Product, product
if mongoid?
assert_match "#<Product _id: ", product.inspect
else
assert_match "#<Product id: ", product.i... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/query_test.rb | Ruby | mit | 6,709 | master | 3,432 | require_relative "test_helper"
class QueryTest < Minitest::Test
def test_basic
store_names ["Milk", "Apple"]
query = Product.search("milk", body: {query: {match_all: {}}})
assert_equal ["Apple", "Milk"], query.map(&:name).sort
end
def test_with_uneffective_min_score
store_names ["Milk", "Milk2"]... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/index_cache_test.rb | Ruby | mit | 6,709 | master | 1,244 | require_relative "test_helper"
class IndexCacheTest < Minitest::Test
def setup
Product.class_variable_get(:@@searchkick_index_cache).clear
end
def test_default
object_id = Product.searchkick_index.object_id
3.times do
assert_equal object_id, Product.searchkick_index.object_id
end
end
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/highlight_test.rb | Ruby | mit | 6,709 | master | 4,462 | require_relative "test_helper"
class HighlightTest < Minitest::Test
def test_basic
store_names ["Two Door Cinema Club"]
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", highlight: true).highlights.first[:name]
end
def test_with_highlights
store_names ["Two Door Cinema Club"]
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/search_synonyms_test.rb | Ruby | mit | 6,709 | master | 2,453 | require_relative "test_helper"
class SearchSynonymsTest < Minitest::Test
def setup
super
setup_speaker
end
def test_bleach
store_names ["Clorox Bleach", "Kroger Bleach"]
assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"]
end
def test_burger_buns
store_names ["Hamburger Buns"]
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/log_subscriber_test.rb | Ruby | mit | 6,709 | master | 2,246 | require_relative "test_helper"
class LogSubscriberTest < Minitest::Test
def test_create
output = capture_logs do
Product.create!(name: "Product A")
end
assert_match "Product Store", output
end
def test_update
product = Product.create!(name: "Product A")
output = capture_logs do
p... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/exclude_test.rb | Ruby | mit | 6,709 | master | 1,339 | require_relative "test_helper"
class ExcludeTest < Minitest::Test
def test_butter
store_names ["Butter Tub", "Peanut Butter Tub"]
assert_search "butter", ["Butter Tub"], exclude: ["peanut butter"]
end
def test_butter_word_start
store_names ["Butter Tub", "Peanut Butter Tub"]
assert_search "butte... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/select_test.rb | Ruby | mit | 6,709 | master | 3,890 | require_relative "test_helper"
class SelectTest < Minitest::Test
def test_basic
store [{name: "Product A", store_id: 1}]
result = Product.search("product", load: false, select: [:name, :store_id]).first
assert_equal %w(id name store_id), result.to_h.keys.reject { |k| k.start_with?("_") }.sort
assert_... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/language_test.rb | Ruby | mit | 6,709 | master | 4,677 | require_relative "test_helper"
class LanguageTest < Minitest::Test
def setup
skip "Requires plugin" unless ci? || ENV["TEST_LANGUAGE"]
Song.destroy_all
end
def test_chinese
skip if ci?
# requires https://github.com/medcl/elasticsearch-analysis-ik
with_options({language: "chinese"}) do
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/order_test.rb | Ruby | mit | 6,709 | master | 2,398 | require_relative "test_helper"
class OrderTest < Minitest::Test
def test_hash
store_names ["Product A", "Product B", "Product C", "Product D"]
assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
assert_order_relation ["Product D", "Product C", "Product B", "... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/geo_shape_test.rb | Ruby | mit | 6,709 | master | 3,046 | require_relative "test_helper"
class GeoShapeTest < Minitest::Test
def setup
setup_region
store [
{
name: "Region A",
text: "The witch had a cat",
territory: {
type: "polygon",
coordinates: [[[30, 40], [35, 45], [40, 40], [40, 30], [30, 30], [30, 40]]]
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/index_options_test.rb | Ruby | mit | 6,709 | master | 3,190 | require_relative "test_helper"
class IndexOptionsTest < Minitest::Test
def setup
Song.destroy_all
end
def test_case_sensitive
with_options({case_sensitive: true}) do
store_names ["Test", "test"]
assert_search "test", ["test"], {misspellings: false}
end
end
def test_no_stemming
w... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/parameters_test.rb | Ruby | mit | 6,709 | master | 4,036 | require_relative "test_helper"
class ParametersTest < Minitest::Test
def setup
require "action_controller"
super
end
def test_options
params = ActionController::Parameters.new({store_id: 1})
assert_raises(ActionController::UnfilteredParameters) do
Product.search("*", **params)
end
en... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/reindex_test.rb | Ruby | mit | 6,709 | master | 10,682 | require_relative "test_helper"
class ReindexTest < Minitest::Test
def test_record_inline
store_names ["Product A", "Product B"], reindex: false
product = Product.find_by!(name: "Product A")
assert_equal true, product.reindex(refresh: true)
assert_search "product", ["Product A"]
end
def test_rec... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/match_test.rb | Ruby | mit | 6,709 | master | 8,914 | require_relative "test_helper"
class MatchTest < Minitest::Test
# exact
def test_match
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
assert_search "milk", ["Milk", "Whole Milk", "Fat Free Milk"]
end
def test_case
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
assert_search "MILK", ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/knn_test.rb | Ruby | mit | 6,709 | master | 8,722 | require_relative "test_helper"
class KnnTest < Minitest::Test
def setup
skip unless Searchkick.knn_support?
super
# prevent null_pointer_exception with OpenSearch 3
Product.reindex if Searchkick.opensearch? && !Searchkick.server_below?("3.0.0")
end
def test_basic
store [{name: "A", embeddin... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/unscope_test.rb | Ruby | mit | 6,709 | master | 803 | require_relative "test_helper"
class UnscopeTest < Minitest::Test
def setup
@@once ||= Artist.reindex
Artist.unscoped.destroy_all
end
def test_reindex
create_records
Artist.reindex
assert_search "*", ["Test", "Test 2"]
assert_search "*", ["Test", "Test 2"], {load: false}
end
def t... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/callbacks_test.rb | Ruby | mit | 6,709 | master | 2,687 | require_relative "test_helper"
class CallbacksTest < Minitest::Test
def test_false
Searchkick.callbacks(false) do
store_names ["Product A", "Product B"]
end
assert_search "product", []
end
def test_bulk
Searchkick.callbacks(:bulk) do
store_names ["Product A", "Product B"]
end
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/multi_search_test.rb | Ruby | mit | 6,709 | master | 1,490 | require_relative "test_helper"
class MultiSearchTest < Minitest::Test
def test_basic
store_names ["Product A"]
store_names ["Store A"], Store
products = Product.search("*")
stores = Store.search("*")
Searchkick.multi_search([products, stores])
assert_equal ["Product A"], products.map(&:name)
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/misspellings_test.rb | Ruby | mit | 6,709 | master | 3,742 | require_relative "test_helper"
class MisspellingsTest < Minitest::Test
def test_false
store_names ["abc", "abd", "aee"]
assert_search "abc", ["abc"], misspellings: false
end
def test_distance
store_names ["abbb", "aabb"]
assert_search "aaaa", ["aabb"], misspellings: {distance: 2}
end
def te... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/index_test.rb | Ruby | mit | 6,709 | master | 4,607 | require_relative "test_helper"
class IndexTest < Minitest::Test
def setup
super
setup_region
end
def test_tokens
assert_equal ["dollar", "dollartre", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_index")
end
def test_tokens_analyzer
assert_equal ["dollar", "t... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/routing_test.rb | Ruby | mit | 6,709 | master | 1,017 | require_relative "test_helper"
class RoutingTest < Minitest::Test
def test_query
query = Store.search("Dollar Tree", routing: "Dollar Tree")
assert_equal query.params[:routing], "Dollar Tree"
end
def test_mappings
mappings = Store.searchkick_index.index_options[:mappings]
assert_equal mappings[:... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/search_test.rb | Ruby | mit | 6,709 | master | 2,399 | require_relative "test_helper"
class SearchTest < Minitest::Test
def test_search_relation
error = assert_raises(Searchkick::Error) do
Product.all.search("*")
end
assert_equal "search must be called on model, not relation", error.message
end
def test_unscoped
if mongoid?
Product.unsco... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/results_test.rb | Ruby | mit | 6,709 | master | 1,677 | require_relative "test_helper"
class ResultsTest < Minitest::Test
def test_array_methods
store_names ["Product A", "Product B"]
products = Product.search("product")
assert_equal 2, products.count
assert_equal 2, products.size
assert_equal 2, products.length
assert products.any?
refute pro... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/support/mongoid.rb | Ruby | mit | 6,709 | master | 1,557 | Mongoid.logger = $logger
Mongo::Logger.logger = $logger if defined?(Mongo::Logger)
Mongoid.configure do |config|
config.connect_to "searchkick_test", server_selection_timeout: 1
end
class Product
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :store_id, type: Integer
field :in_st... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/support/activerecord.rb | Ruby | mit | 6,709 | master | 2,217 | require "active_record"
# for debugging
ActiveRecord::Base.logger = $logger
# rails does this in activerecord/lib/active_record/railtie.rb
ActiveRecord.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true
# migrations
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":mem... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/support/redis.rb | Ruby | mit | 6,709 | master | 565 | options = {}
options[:logger] = $logger if !defined?(RedisClient)
Searchkick.redis =
if !defined?(Redis)
RedisClient.config.new_pool
elsif defined?(ConnectionPool)
ConnectionPool.new { Redis.new(**options) }
else
Redis.new(**options)
end
module RedisInstrumentation
def call(command, redis_config... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/support/helpers.rb | Ruby | mit | 6,709 | master | 3,446 | class Minitest::Test
include ActiveJob::TestHelper
def setup
[Product, Store].each do |model|
setup_model(model)
end
end
protected
def setup_animal
setup_model(Animal)
end
def setup_region
setup_model(Region)
end
def setup_speaker
setup_model(Speaker)
end
def setup_... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/support/apartment.rb | Ruby | mit | 6,709 | master | 768 | module Rails
def self.env
ENV["RACK_ENV"]
end
end
tenants = ["tenant1", "tenant2"]
Apartment.configure do |config|
config.tenant_names = tenants
config.database_schema_file = false
config.excluded_models = ["Product", "Store", "Region", "Speaker", "Animal", "Dog", "Cat", "Sku", "Song", "Band"]
end
class... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/models/speaker.rb | Ruby | mit | 6,709 | master | 602 | class Speaker
searchkick \
conversions_v1: ["conversions_a", "conversions_b"],
search_synonyms: [
["clorox", "bleach"],
["burger", "hamburger"],
["bandaids", "bandages"],
["UPPERCASE", "lowercase"],
"led => led,lightbulb",
"halogen lamp => lightbulb",
["United States ... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/models/product.rb | Ruby | mit | 6,709 | master | 1,671 | class Product
searchkick \
synonyms: [
["clorox", "bleach"],
["burger", "hamburger"],
["bandaid", "bandages"],
["UPPERCASE", "lowercase"],
"lightbulb => led,lightbulb",
"lightbulb => halogenlamp"
],
suggest: [:name, :color],
conversions_v1: [:conversions],
conve... |
github | ankane/searchkick | https://github.com/ankane/searchkick | test/models/store.rb | Ruby | mit | 6,709 | master | 246 | class Store
mappings = {
properties: {
name: {type: "text"}
}
}
searchkick \
routing: true,
merge_mappings: true,
mappings: mappings
def search_document_id
id
end
def search_routing
name
end
end |
github | ankane/searchkick | https://github.com/ankane/searchkick | examples/semantic.rb | Ruby | mit | 6,709 | master | 1,307 | require "bundler/setup"
require "active_record"
require "elasticsearch" # or "opensearch-ruby"
require "informers"
require "searchkick"
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define do
create_table :products do |t|
... |
github | ankane/searchkick | https://github.com/ankane/searchkick | examples/hybrid.rb | Ruby | mit | 6,709 | master | 1,844 | require "bundler/setup"
require "active_record"
require "elasticsearch" # or "opensearch-ruby"
require "informers"
require "searchkick"
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define do
create_table :products do |t|
... |
github | kkuchta/css-only-chat | https://github.com/kkuchta/css-only-chat | server.rb | Ruby | mit | 6,588 | master | 7,594 | require 'redis'
require 'json'
require 'securerandom'
# Since some requests (intentionally) never complete, ctrl-c won't kill this
# server. Let's make sure it does.
Signal.trap(2) { exit }
# Misc redis keys
NEW_MESSAGE_CHANNEL = 'new_message_channel'.freeze
UPDATED_CLIENT_CHANNEL = 'updated_client_channel'.freeze
M... |
github | kkuchta/css-only-chat | https://github.com/kkuchta/css-only-chat | config.ru | Ruby | mit | 6,588 | master | 210 | require 'rubygems'
require 'bundler'
require 'pry'
Bundler.require
# Loads a .env file to pick up your environment variables
require 'dotenv'
Dotenv.load
use Rack::Chunked
require './server'
run Server.new |
github | busyloop/lolcat | https://github.com/busyloop/lolcat | lolcat.gemspec | Ruby | bsd-3-clause | 6,525 | master | 806 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "lolcat/version"
Gem::Specification.new do |s|
s.name = "lolcat"
s.version = Lolcat::VERSION
s.authors = ["Moe"]
s.email = ["moe@busyloop.net"]
s.homepage = "https://github.com/busyloop/lolcat"
s.descript... |
github | busyloop/lolcat | https://github.com/busyloop/lolcat | lib/lolcat.rb | Ruby | bsd-3-clause | 6,525 | master | 1,609 | # Copyright (c) 2016, moe@busyloop.net
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of condition... |
github | busyloop/lolcat | https://github.com/busyloop/lolcat | lib/lolcat/lol.rb | Ruby | bsd-3-clause | 6,525 | master | 4,233 | # Copyright (c) 2016, moe@busyloop.net
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of condition... |
github | busyloop/lolcat | https://github.com/busyloop/lolcat | lib/lolcat/cat.rb | Ruby | bsd-3-clause | 6,525 | master | 4,887 | # Copyright (c) 2016, moe@busyloop.net
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of condition... |
github | ankane/chartkick | https://github.com/ankane/chartkick | chartkick.gemspec | Ruby | mit | 6,526 | master | 537 | require_relative "lib/chartkick/version"
Gem::Specification.new do |spec|
spec.name = "chartkick"
spec.version = Chartkick::VERSION
spec.summary = "Create beautiful JavaScript charts with one line of Ruby"
spec.homepage = "https://chartkick.com"
spec.license = "MIT"
spec.au... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.