Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 3, 2024
1 parent d5f0301 commit bcdfb80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/knn_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require_relative "test_helper"

class KnnTest < Minitest::Test
def setup
skip unless knn_support?
super
end

def test_works
store [{name: "A", embedding: [1, 2, 3]}, {name: "B", embedding: [-1, -2, -3]}]
assert_order "*", ["A", "B"], knn: {embedding: [1, 2, 3]}
Expand Down
2 changes: 1 addition & 1 deletion test/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Product
filterable: [:name, :color, :description],
similarity: "BM25",
match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil,
knn: {embedding: {dimensions: 3}}
knn: knn_support? ? {embedding: {dimensions: 3}} : nil

attr_accessor :conversions, :user_ids, :aisle, :details

Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@

ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["VERBOSE"]

def knn_support?
if Searchkick.opensearch?
!Searchkick.server_below?("2.4.0", true)
else
!Searchkick.server_below?("8.0.0")
end
end

if defined?(Mongoid)
require_relative "support/mongoid"
else
Expand Down

0 comments on commit bcdfb80

Please sign in to comment.