<commit_before>require 'spec_helper'
describe Spree::Search::Elasticsearch do
  before do
    @product1 = create(:product, :name => "Nike Golf women's Lunar Golf Shoe", :price => 80.00)
    @product2 = create(:product, :name => "Nike Golf men's Lunar Golf Shoe", :price => 85.00)
    @product3 = create(:product, :name => "BOSS Black by <NAME> Men's Cauro Oxford", :price => 166.32)
    @product4 = create(:product, :name => "BOSS Orange by <NAME> Men's Ofero Wingtip", :price => 215257)
    Spree::Product.__elasticsearch__.client.indices.refresh
  end

  context "#search" do
    it "should find the women's shoe" do
      searcher = Spree::Search::Elasticsearch.new(:keywords => "women's", :per_page => "")
      response = searcher.retrieve_products
      expect(response.to_a.length).to eql(1)
      expect(response.to_a.first.name).to eql(@product1.name)
    end

    it "should find the mens shoe" do
      search = Spree::Search::Elasticsearch.new(:keywords => "men's", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(3)
      expect(response.to_a.first.name).to eql(@product3.name)
    end

    it "should find the mens and womens shoes, but the womens shoe should be first" do
      search = Spree::Search::Elasticsearch.new(:keywords => "women's golf shoe", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
      expect(response.to_a.first.name).to eql(@product1.name)
    end

    it "should find the mens and womens shoes, but the mens shoe should be first" do
      search = Spree::Search::Elasticsearch.new(:keywords => "men's nike golf shoe", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(4)
      expect(response.to_a.first.name).to eql(@product2.name)
    end

    it "should return page one of two pages of results" do
      search = Spree::Search::Elasticsearch.new(:keywords => "mens", :per_page => "2")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
      expect(response.to_a.first).to eql(@product3)
      expect(response.to_a.last).to eql(@product4)
    end

    it "should return page two of two pages of results" do
      search = Spree::Search::Elasticsearch.new(:keywords => "mens", :per_page => "2", :page => "2")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(1)
      expect(response.to_a.first).to eql(@product2)
    end
  end
end<commit_msg>Added extra tests<commit_after>require 'spec_helper'
describe Spree::Search::Elasticsearch do
  before do
    @product1 = create(:product, :name => "Nike Golf women's Lunar Golf Shoe", :price => 80.00)
    @product2 = create(:product, :name => "Nike Golf men's Lunar Golf Shoe", :price => 85.00)
    @product3 = create(:product, :name => "BOSS Black by <NAME> Men's Cauro Oxford", :price => 166.32)
    @product4 = create(:product, :name => "BOSS Orange by <NAME> Men's Ofero Wingtip", :price => 215257)
    Spree::Product.__elasticsearch__.client.indices.refresh
  end

  context "#search" do
    it "should find the women's shoe" do
      searcher = Spree::Search::Elasticsearch.new(:keywords => "women's", :per_page => "")
      response = searcher.retrieve_products
      expect(response.to_a.length).to eql(1)
      expect(response.to_a.first.name).to eql(@product1.name)
    end

    it "should find the mens shoe" do
      search = Spree::Search::Elasticsearch.new(:keywords => "men's", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(3)
      expect(response.to_a.first.name).to eql(@product3.name)
    end

    it "should find the mens and womens shoes, but the womens shoe should be first" do
      search = Spree::Search::Elasticsearch.new(:keywords => "women's golf shoe", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
      expect(response.to_a.first.name).to eql(@product1.name)
    end

    it "should find the mens and womens shoes, but the mens shoe should be first" do
      search = Spree::Search::Elasticsearch.new(:keywords => "men's nike golf shoe", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(4)
      expect(response.to_a.first.name).to eql(@product2.name)
    end

    it "should return page one of two pages of results" do
      search = Spree::Search::Elasticsearch.new(:keywords => "mens", :per_page => "2")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
      expect(response.to_a.first).to eql(@product3)
      expect(response.to_a.last).to eql(@product4)
    end

    it "should return page two of two pages of results" do
      search = Spree::Search::Elasticsearch.new(:keywords => "mens", :per_page => "2", :page => "2")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(1)
      expect(response.to_a.first).to eql(@product2)
    end

    it "should match the synonym" do
      search = Spree::Search::Elasticsearch.new(:keywords => "신발", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
      expect(response.to_a.first).to eql(@product1)
    end

    it "should match the multiple synonym search" do
      search = Spree::Search::Elasticsearch.new(:keywords => "남자 신발", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(4)
    end

    it "should match a name that is a single word in Korean but is multiple words in english" do
      search = Spree::Search::Elasticsearch.new(:keywords => "휴고보스", :per_page => "")
      response = search.retrieve_products
      expect(response.to_a.length).to eql(2)
    end

  end
end
{'fraction_non_alphanumeric': 0.13576215844646847, 'fraction_numerical': 0.014091768345076474, 'mean_word_length': 3.5718774548311076, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3503402', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1874, 'n_words': 474}