Project

General

Profile

Feature #38402 » any-searchable-text-should-perform-AND-search.patch

Go MAEDA, 2023-04-05 18:38

View differences:

app/models/issue_query.rb
792 792
    end
793 793

  
794 794
    fetcher = Redmine::Search::Fetcher.new(
795
      question, User.current, ['issue'], projects, attachments: '0'
795
      question, User.current, ['issue'], projects, all_words: (operator != '!~'), attachments: '0'
796 796
    )
797 797
    ids = fetcher.result_ids.map(&:last)
798 798
    if ids.present?
test/unit/query_test.rb
859 859
    assert_equal [1, 2, 3], result.map(&:id).sort
860 860
  end
861 861

  
862
  def test_filter_any_searchable_with_multiple_words
863
    User.current = User.find(1)
864
    query = IssueQuery.new(
865
      :name => '_',
866
      :filters => {
867
        'any_searchable' => {
868
          :operator => '~',
869
          :values => ['recipe categories']
870
        }
871
      }
872
    )
873
    result = find_issues_with_query(query)
874
    assert_equal [2], result.map(&:id)
875
  end
876

  
877
  def test_filter_any_searchable_with_multiple_words_negative
878
    User.current = User.find(1)
879

  
880
    query_result_ids = ->(op, value) do
881
      query = IssueQuery.new(
882
        :name => '_',
883
        :filters => {'any_searchable' => {:operator => op, :values => [value]}}
884
      )
885
      find_issues_with_query(query).map(&:id).sort
886
    end
887

  
888
    ids_word1 = query_result_ids.call('~', 'recipe')
889
    ids_word2 = query_result_ids.call('~', 'categories')
890
    ids = query_result_ids.call('!~', 'recipe categories')
891

  
892
    # Neither "recipe" nor "categories" are in the subject, description, notes, etc.
893
    assert ids, Issue.ids.sort - ids_word1 - ids_word2
894
  end
895

  
862 896
  def test_filter_any_searchable_no_matches
863 897
    User.current = User.find(1)
864 898
    query = IssueQuery.new(
(5-5/8)