The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix semantic search tests when running on mysql and enable all appdbs in CI (#62966)
appleby4b99970499b6
diff --git a/.github/workflows/semantic-search.yml b/.github/workflows/semantic-search.ymlindex f63e2575380..e7d187202ab 100644--- a/.github/workflows/semantic-search.yml+++ b/.github/workflows/semantic-search.yml@@ -12,7 +12,7 @@ concurrency:cancel-in-progress: truejobs:- semantic-search-tests-pgvector:+ semantic-search-tests-h2:if: ${{ !inputs.skip }}runs-on: ubuntu-22.04timeout-minutes: 60@@ -20,9 +20,69 @@ jobs:fail-fast: falsematrix:version:- - name: pgvector pg16- junit-name: semantic-search-tests-pgvector-16- image: pgvector/pgvector:pg16+ - name: H2 with pgvector pg16+ junit-name: semantic-search-tests-h2-pgvector-16+ pgvector-image: pgvector/pgvector:pg16+ job:+ - name: Semantic Search Tests+ build-static-viz: false+ test-args: >-+ :only '"enterprise/backend/test/metabase_enterprise/semantic_search"'+ exclude-tag: ':mb/driver-tests'++ services:+ pgvector:+ image: ${{ matrix.version.pgvector-image }}+ ports:+ - "5432:5432"+ env:+ POSTGRES_DB: mb_semantic_search+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ env:+ MB_PGVECTOR_DB_URL: 'jdbc:postgres://localhost:5432/mb_semantic_search?user=postgres&password=postgres'+ CI: 'true'+ name: "${{ matrix.version.name }} ${{ matrix.job.name }}"+ steps:+ - uses: actions/checkout@v4+ - name: Test ${{ matrix.version.name }}+ uses: ./.github/actions/test-driver+ with:+ build-static-viz: ${{ matrix.job.build-static-viz }}+ junit-name: ${{ matrix.version.junit-name }}+ test-args: >-+ ${{ matrix.job.test-args }}+ :exclude-tags '[${{ matrix.job.exclude-tag }}]'+ - name: Upload Test Results+ uses: ./.github/actions/upload-test-results+ if: always()+ with:+ input-path: ./target/junit/+ output-name: ${{ github.job }}+ bucket: ${{ vars.AWS_S3_TEST_RESULTS_BUCKET }}+ aws-access-key-id: ${{ secrets.AWS_TEST_RESULTS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_TEST_RESULTS_SECRET_ACCESS_KEY }}+ aws-region: ${{ vars.AWS_REGION }}+ trunk-api-token: ${{ secrets.TRUNK_API_TOKEN }}++ semantic-search-tests-mariadb:+ if: ${{ !inputs.skip }}+ runs-on: ubuntu-22.04+ timeout-minutes: 60+ strategy:+ fail-fast: false+ matrix:+ version:+ - name: MariaDB 10.2 with pgvector pg16+ junit-name: semantic-search-tests-mariadb-10-2+ mariadb-image: circleci/mariadb:10.2.23+ pgvector-image: pgvector/pgvector:pg16+ env:+ enable-ssl-tests: 'false'+ - name: MariaDB Latest with pgvector pg16+ junit-name: semantic-search-tests-mariadb-latest+ mariadb-image: circleci/mariadb:latest+ pgvector-image: pgvector/pgvector:pg16env:enable-ssl-tests: 'false'job:@@ -34,31 +94,183 @@ jobs:services:pgvector:- image: ${{ matrix.version.image }}+ image: ${{ matrix.version.pgvector-image }}ports:- "5432:5432"env:POSTGRES_DB: mb_semantic_searchPOSTGRES_USER: postgresPOSTGRES_PASSWORD: postgres+ mysql:+ image: ${{ matrix.version.mariadb-image }}+ ports:+ - "3306:3306"+ env:+ MYSQL_ALLOW_EMPTY_PASSWORD: true+ MYSQL_DATABASE: circle_testenv:- # Only run old migrations tests on pushes to master or release branches. All other branches should skip tests- # with the tag `mb/old-migrations-test`. `__ADDITIONAL_EXCLUDED_TAG__` is not used anywhere outside of splicing- # it in to the command below.- __ADDITIONAL_EXCLUDED_TAG__: >-- ${{- (- github.event_name == 'push' &&- (- github.ref == 'master' ||- startsWith(github.ref, 'release-')- ) &&- ''- ) ||- ':mb/old-migrations-test'- }}+ CI: 'true'+ DRIVERS: mysql+ MB_DB_TYPE: mysql+ MB_DB_HOST: localhost+ MB_DB_PORT: 3306+ MB_DB_DBNAME: circle_test+ MB_DB_USER: root+ MB_MYSQL_TEST_USER: rootMB_PGVECTOR_DB_URL: 'jdbc:postgres://localhost:5432/mb_semantic_search?user=postgres&password=postgres'+ name: "${{ matrix.version.name }} ${{ matrix.job.name }}"+ steps:+ - uses: actions/checkout@v4+ - name: Test ${{ matrix.version.name }}+ uses: ./.github/actions/test-driver+ with:+ build-static-viz: ${{ matrix.job.build-static-viz }}+ junit-name: ${{ matrix.version.junit-name }}+ test-args: >-+ ${{ matrix.job.test-args }}+ :exclude-tags '[${{ matrix.job.exclude-tag }}]'+ - name: Upload Test Results+ uses: ./.github/actions/upload-test-results+ if: always()+ with:+ input-path: ./target/junit/+ output-name: ${{ github.job }}+ bucket: ${{ vars.AWS_S3_TEST_RESULTS_BUCKET }}+ aws-access-key-id: ${{ secrets.AWS_TEST_RESULTS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_TEST_RESULTS_SECRET_ACCESS_KEY }}+ aws-region: ${{ vars.AWS_REGION }}+ trunk-api-token: ${{ secrets.TRUNK_API_TOKEN }}++ semantic-search-tests-mysql:+ if: ${{ !inputs.skip }}+ runs-on: ubuntu-22.04+ timeout-minutes: 60+ strategy:+ fail-fast: false+ matrix:+ version:+ - name: MySQL 8.0 with pgvector pg16+ junit-name: semantic-search-tests-mysql-8-0+ mysql-image: cimg/mysql:8.0+ pgvector-image: pgvector/pgvector:pg16+ env:+ enable-ssl-tests: 'false'+ - name: MySQL Latest with pgvector pg16+ junit-name: semantic-search-tests-mysql-latest+ mysql-image: mysql:latest+ pgvector-image: pgvector/pgvector:pg16+ env:+ enable-ssl-tests: 'true'+ job:+ - name: Semantic Search Tests+ build-static-viz: false+ test-args: >-+ :only '"enterprise/backend/test/metabase_enterprise/semantic_search"'+ exclude-tag: ':mb/driver-tests'++ services:+ pgvector:+ image: ${{ matrix.version.pgvector-image }}+ ports:+ - "5432:5432"+ env:+ POSTGRES_DB: mb_semantic_search+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ mysql:+ image: ${{ matrix.version.mysql-image }}+ ports:+ - "3306:3306"+ env:+ MYSQL_ALLOW_EMPTY_PASSWORD: true+ MYSQL_DATABASE: circle_test+ env:CI: 'true'+ DRIVERS: mysql+ MB_DB_TYPE: mysql+ MB_DB_HOST: localhost+ MB_DB_PORT: 3306+ MB_DB_DBNAME: circle_test+ MB_DB_USER: root+ MB_MYSQL_TEST_USER: root+ MB_PGVECTOR_DB_URL: 'jdbc:postgres://localhost:5432/mb_semantic_search?user=postgres&password=postgres'+ name: "${{ matrix.version.name }} ${{ matrix.job.name }}"+ steps:+ - uses: actions/checkout@v4+ - name: Test ${{ matrix.version.name }}+ uses: ./.github/actions/test-driver+ with:+ build-static-viz: ${{ matrix.job.build-static-viz }}+ junit-name: ${{ matrix.version.junit-name }}+ test-args: >-+ ${{ matrix.job.test-args }}+ :exclude-tags '[${{ matrix.job.exclude-tag }}]'+ - name: Upload Test Results+ uses: ./.github/actions/upload-test-results+ if: always()+ with:+ input-path: ./target/junit/+ output-name: ${{ github.job }}+ bucket: ${{ vars.AWS_S3_TEST_RESULTS_BUCKET }}+ aws-access-key-id: ${{ secrets.AWS_TEST_RESULTS_ACCESS_KEY_ID }}+ aws-secret-access-key: ${{ secrets.AWS_TEST_RESULTS_SECRET_ACCESS_KEY }}+ aws-region: ${{ vars.AWS_REGION }}+ trunk-api-token: ${{ secrets.TRUNK_API_TOKEN }}++ semantic-search-tests-postgres:+ if: ${{ !inputs.skip }}+ runs-on: ubuntu-22.04+ timeout-minutes: 60+ strategy:+ fail-fast: false+ matrix:+ version:+ - name: Postgres 12.x with pgvector pg16+ junit-name: semantic-search-tests-postgres-12+ postgres-image: postgres:12-alpine+ pgvector-image: pgvector/pgvector:pg16+ env:+ enable-ssl-tests: 'false'+ - name: Postgres Latest with pgvector pg16+ junit-name: semantic-search-tests-postgres-latest+ postgres-image: postgres:latest+ pgvector-image: pgvector/pgvector:pg16+ env:+ enable-ssl-tests: 'true'+ job:+ - name: Semantic Search Tests+ build-static-viz: false+ test-args: >-+ :only '"enterprise/backend/test/metabase_enterprise/semantic_search"'+ exclude-tag: ':mb/driver-tests'++ services:+ pgvector:+ image: ${{ matrix.version.pgvector-image }}+ ports:+ - "5432:5432"+ env:+ POSTGRES_DB: mb_semantic_search+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ postgres:+ image: ${{ matrix.version.postgres-image }}+ ports:+ - "5433:5432"+ env:+ POSTGRES_USER: mb_test+ POSTGRES_DB: mb_test+ POSTGRES_HOST_AUTH_METHOD: trust+ env:+ CI: 'true'+ DRIVERS: postgres+ MB_DB_TYPE: postgres+ MB_DB_PORT: 5433+ MB_DB_HOST: localhost+ MB_DB_DBNAME: mb_test+ MB_DB_USER: mb_test+ MB_POSTGRESQL_TEST_USER: mb_test+ MB_PGVECTOR_DB_URL: 'jdbc:postgres://localhost:5432/mb_semantic_search?user=postgres&password=postgres'name: "${{ matrix.version.name }} ${{ matrix.job.name }}"steps:- uses: actions/checkout@v4@@ -69,7 +281,7 @@ jobs:junit-name: ${{ matrix.version.junit-name }}test-args: >-${{ matrix.job.test-args }}- :exclude-tags '[ ${{ matrix.job.exclude-tag }} ${{ env.__ADDITIONAL_EXCLUDED_TAG__ }}]'+ :exclude-tags '[${{ matrix.job.exclude-tag }}]'- name: Upload Test Resultsuses: ./.github/actions/upload-test-resultsif: always()@@ -84,7 +296,10 @@ jobs:semantic-search-tests-result:needs:- - semantic-search-tests-pgvector+ - semantic-search-tests-h2+ - semantic-search-tests-mariadb+ - semantic-search-tests-mysql+ - semantic-search-tests-postgresruns-on: ubuntu-latesttimeout-minutes: 5name: semantic-search-tests-resultdiff --git a/enterprise/backend/src/metabase_enterprise/semantic_search/scoring.clj b/enterprise/backend/src/metabase_enterprise/semantic_search/scoring.cljindex 7403c4e791e..c92cd5d842f 100644--- a/enterprise/backend/src/metabase_enterprise/semantic_search/scoring.clj+++ b/enterprise/backend/src/metabase_enterprise/semantic_search/scoring.clj@@ -179,11 +179,11 @@"The appdb-based scorers for search ranking results. Like `base-scorers`, but for scorers that need to query the appdb."[{:keys [limit-int] :as search-ctx}](when-not (and limit-int (zero? limit-int))- (merge {:bookmarked search.scoring/bookmark-score-expr}- (when-not (= :mysql (mdb/db-type))- ;; The :user-recency scorer needs to be modified to work with mysql / mariadb (BOT-360)- {:user-recency (search.scoring/inverse-duration- (search.scoring/user-recency-expr search-ctx) [:now] search.config/stale-time-in-days)}))))+ (when-not (= :mysql (mdb/db-type))+ ;; The appdb scorers need to be modified to work with mysql / mariadb (BOT-360)+ {:bookmarked search.scoring/bookmark-score-expr+ :user-recency (search.scoring/inverse-duration+ (search.scoring/user-recency-expr search-ctx) [:now] search.config/stale-time-in-days)})))(defn with-appdb-scores"Add appdb-based scores to `search-results` and re-sort the results based on the new combined scores.diff --git a/enterprise/backend/test/metabase_enterprise/semantic_search/core_test.clj b/enterprise/backend/test/metabase_enterprise/semantic_search/core_test.cljindex bfe69a4127b..eeab9afcd6a 100644--- a/enterprise/backend/test/metabase_enterprise/semantic_search/core_test.clj+++ b/enterprise/backend/test/metabase_enterprise/semantic_search/core_test.clj@@ -4,8 +4,11 @@[metabase-enterprise.semantic-search.core :as semantic.core][metabase-enterprise.semantic-search.pgvector-api :as semantic.pgvector-api][metabase-enterprise.semantic-search.test-util :as semantic.tu]+ [metabase.app-db.core :as mdb][metabase.search.appdb.core :as appdb][metabase.search.engine :as search.engine]+ [metabase.search.in-place.legacy :as in-place.legacy]+ [metabase.search.in-place.scoring :as in-place.scoring][metabase.search.settings :as search.settings][metabase.test :as mt][metabase.test.fixtures :as fixtures]))@@ -14,63 +17,75 @@(fixtures/initialize :db)#'semantic.tu/once-fixture))-(deftest appdb-available-with-semantic+(deftest fallback-engine-available-with-semantic-test(mt/with-premium-features #{:semantic-search}(mt/with-temporary-setting-values [search.settings/search-engine "semantic"](with-open [_ (semantic.tu/open-temp-index!)](semantic.tu/cleanup-index-metadata! semantic.tu/db semantic.tu/mock-index-metadata)(semantic.tu/with-index!- (is (search.engine/supported-engine? :search.engine/appdb)))))))+ (is (search.engine/supported-engine? (if (= :mysql (mdb/db-type))+ ;; appdb is not supported on :mysql, should fallback to in-place+ :search.engine/in-place+ :search.engine/appdb))))))))(deftest api-engine-switching-test(mt/with-premium-features #{:semantic-search}(mt/with-temporary-setting-values [search.settings/search-engine "semantic"](with-open [_ (semantic.tu/open-temp-index!)]- ;; Disable falling back to appdb search engine when not enough semantic results are returned+ ;; Disable falling back to appdb / in-place search engine when not enough semantic results are returned(mt/with-temporary-setting-values [semantic-search-min-results-threshold 0]- (testing "API defaults to semantic engine when configured"- (let [semantic-called? (atom false)- appdb-called? (atom false)]- (with-redefs [semantic.pgvector-api/query- (fn [& _]- (reset! semantic-called? true)- {:results [{:id 1 :name "semantic-result" :model "card" :collection_id 1 :score 0}]- :raw-count 0})- appdb/results- (fn [_]- (reset! appdb-called? true)- [{:id 2 :name "appdb-result" :model "card" :collection_id 1 :score 0.9}])]-+ (let [semantic-called? (atom false)+ appdb-called? (atom false)+ legacy-called? (atom false)+ reset-called-atoms! #(do (reset! semantic-called? false)+ (reset! appdb-called? false)+ (reset! legacy-called? false))]+ (with-redefs [semantic.pgvector-api/query+ (fn [& _]+ (reset! semantic-called? true)+ {:results [{:id 1 :name "semantic-result" :model "card" :collection_id 1 :score 0}]+ :raw-count 0})+ appdb/results+ (fn [_]+ (reset! appdb-called? true)+ [{:id 2 :name "appdb-result" :model "card" :collection_id 1 :score 0.9}])+ in-place.scoring/score-and-result+ (fn [result _]+ {:result (dissoc result :score)+ :score (:score result)})+ in-place.legacy/results+ (fn [_]+ (reset! legacy-called? true)+ [{:id 2 :name "legacy-result" :model "card" :collection_id 1 :score 0.7}])]+ (testing "API defaults to semantic engine when configured"(let [response (mt/user-http-request :crowberto :get 200 "search" :q "test")](is @semantic-called? "Semantic search should be called by default")(is (not @appdb-called?) "AppDB search should not be called by default")- (is (= "search.engine/semantic" (:engine response)))))))-- (testing "API can override engine with search_engine=appdb parameter"- (let [semantic-called? (atom false)- appdb-called? (atom false)]- (with-redefs [semantic.pgvector-api/query- (fn [& _]- (reset! semantic-called? true)- {:results [{:id 1 :name "semantic-result" :model "card" :collection_id 1 :score 0.8}]- :raw-count 0})- appdb/results- (fn [_]- (reset! appdb-called? true)- [{:id 2 :name "appdb-result" :model "card" :collection_id 1 :score 0.9}])]-- (let [response (mt/user-http-request :crowberto :get 200 "search" :q "test" :search_engine "appdb")]- (is (not @semantic-called?) "Semantic search should not be called when overridden")- (is @appdb-called? "AppDB search should be called when specified")- (is (= "search.engine/appdb" (:engine response))))))))))))+ (is (not @legacy-called?) "Legacy search should not be called by default")+ (is (= "search.engine/semantic" (:engine response)))))+ (reset-called-atoms!)+ (testing "API can override engine with search_engine parameter"+ (when (search.engine/supported-engine? :search.engine/appdb)+ (let [response (mt/user-http-request :crowberto :get 200 "search" :q "test" :search_engine "appdb")]+ (is (= "search.engine/appdb" (:engine response)))+ (is @appdb-called? "AppDB search should be called when specified")+ (is (not @semantic-called?) "Semantic search should not be called when overridden")+ (is (not @legacy-called?) "Legacy search should not be called when overridden")))+ (reset-called-atoms!)+ (when (search.engine/supported-engine? :search.engine/in-place)+ (let [response (mt/user-http-request :crowberto :get 200 "search" :q "test" :search_engine "in-place")]+ (is (= "search.engine/in-place" (:engine response)))+ (is @legacy-called? "Legacy search should be called when specified")+ (is (not @semantic-called?) "Semantic search should not be called when overridden")+ (is (not @appdb-called?) "AppDB search should not be called when overridden")))))))))))(def ^:private search-context{:search-string "test" :search-engine :search.engine/semantic})(defn- with-search-engine-mocks!"Sets up search engine mocks for the semantic & appdb backends for testing fallback behavior.- appdb-fn can be a collection of results or a function that takes a context."- [semantic-results appdb-results thunk]+ fallback-results can be a collection of results or a function that takes a context."+ [semantic-results fallback-results thunk](with-redefs [semantic.pgvector-api/query (fn [_pgvector _index-metadata _search-ctx](if (map? semantic-results)semantic-results@@ -78,12 +93,15 @@;; Set raw-count to a non-zero value to ensure fallback logic is;; triggered:raw-count 1}))+ search.engine/score (fn [result _ctx]+ {:result (dissoc result :score)+ :score (:score result)})search.engine/results (fn [ctx](case (:search-engine ctx)- :search.engine/appdb (if (fn? appdb-results)- (appdb-results ctx)- appdb-results)- :search.engine/semantic (semantic.core/results ctx)))]+ :search.engine/semantic (semantic.core/results ctx)+ (if (fn? fallback-results)+ (fallback-results ctx)+ fallback-results)))](thunk)))(defn- make-card-result@@ -93,23 +111,23 @@score (assoc :score score)))(deftest test-semantic-search-fallback-supplementation- (testing "semantic search results below threshold are supplemented with appdb results"+ (testing "semantic search results below threshold are supplemented with fallback results"(mt/with-premium-features #{:semantic-search}(mt/with-temporary-setting-values [semantic-search-min-results-threshold 3]- (let [semantic-result (make-card-result 1 "semantic-card" :score 0.9)- appdb-results [(make-card-result 1 "appdb-card-1")- (make-card-result 2 "appdb-card-2")- (make-card-result 3 "appdb-card-3")- (make-card-result 4 "appdb-dashboard" :model "dashboard")]- search-ctx search-context]- (with-search-engine-mocks! [semantic-result] appdb-results+ (let [semantic-result (make-card-result 1 "semantic-card" :score 0.9)+ fallback-results [(make-card-result 1 "fallback-card-1")+ (make-card-result 2 "fallback-card-2")+ (make-card-result 3 "fallback-card-3")+ (make-card-result 4 "fallback-dashboard" :model "dashboard")]+ search-ctx search-context]+ (with-search-engine-mocks! [semantic-result] fallback-results(fn [](let [results (semantic.core/results search-ctx)](testing "semantic result comes first"(is (= semantic-result (first results))))- (testing "appdb results are appended, and duplicate model/id pairs are removed"- (is (= (rest appdb-results)+ (testing "fallback results are appended, and duplicate model/id pairs are removed"+ (is (= (rest fallback-results)(rest results))))))))))))(deftest test-semantic-search-fallback-failure-resilient@@ -145,31 +163,31 @@(mt/with-premium-features #{:semantic-search}(mt/with-temporary-setting-values [semantic-search-min-results-threshold 3semantic-search-results-limit 5]- (let [semantic-result (make-card-result 1 "semantic-card" :score 0.9)- appdb-results (for [i (range 2 10)]- (make-card-result i (str "appdb-card-" i)))- search-ctx search-context]- (with-search-engine-mocks! [semantic-result] appdb-results+ (let [semantic-result (make-card-result 1 "semantic-card" :score 0.9)+ fallback-results (for [i (range 2 10)]+ (make-card-result i (str "fallback-card-" i)))+ search-ctx search-context]+ (with-search-engine-mocks! [semantic-result] fallback-results(fn [](let [results (semantic.core/results search-ctx)](testing "semantic result is included first"(is (= semantic-result (first results))))- (testing "remaining slots filled with appdb results"+ (testing "remaining slots filled with fallback results"(let [remaining (rest results)](is (= 4 (count remaining)))- (is (every? #(contains? (set appdb-results) %) remaining))))))))))))+ (is (every? #(contains? (set fallback-results) %) remaining))))))))))))(deftest test-semantic-search-fallback-empty-or-nil-search-string(testing "fallback to backup search engine if :search-string is empty or nil"(mt/with-premium-features #{:semantic-search}(let [semantic-results {:results [] :raw-count 0}- appdb-results [(make-card-result 1 "appdb-card-1")]+ fallback-results [(make-card-result 1 "fallback-card-1")]search-ctx search-context]- (with-search-engine-mocks! semantic-results appdb-results+ (with-search-engine-mocks! semantic-results fallback-results(fn [](testing ":search-string is nil"(let [results (semantic.core/results (assoc search-ctx :search-string nil))]- (is (= appdb-results results))))+ (is (= fallback-results results))))(testing ":search-string is empty"(let [results (semantic.core/results (assoc search-ctx :search-string ""))]- (is (= appdb-results results))))))))))+ (is (= fallback-results results))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/semantic_search/scoring_test.clj b/enterprise/backend/test/metabase_enterprise/semantic_search/scoring_test.cljindex 24fa7dfe0d3..22c923a530b 100644--- a/enterprise/backend/test/metabase_enterprise/semantic_search/scoring_test.clj+++ b/enterprise/backend/test/metabase_enterprise/semantic_search/scoring_test.clj@@ -5,6 +5,7 @@[metabase-enterprise.semantic-search.index :as semantic.index][metabase-enterprise.semantic-search.scoring :as semantic.scoring][metabase-enterprise.semantic-search.test-util :as semantic.tu]+ [metabase.app-db.core :as mdb][metabase.search.appdb.scoring-test :refer [with-weights]][metabase.search.config :as search.config][metabase.test :as mt])@@ -213,71 +214,77 @@(is (indifferent? :dashboard "card"))))))(deftest bookmark-test- (let [crowberto (mt/user->id :crowberto)- rasta (mt/user->id :rasta)]- (mt/with-temp [:model/Card {c1 :id} {}- :model/Card {c2 :id} {}]- (testing "bookmarked items are ranker higher"- (with-index-contents!- [{:model "card" :id c1 :name "card normal"}- {:model "card" :id c2 :name "card crowberto loved"}]- (mt/with-temp [:model/CardBookmark _ {:card_id c2 :user_id crowberto}- :model/CardBookmark _ {:card_id c1 :user_id rasta}]- (is (= [["card" c2 "card crowberto loved"]- ["card" c1 "card normal"]]- (search-results :bookmarked "card" {:current-user-id crowberto})))))))+ (mt/with-premium-features #{:semantic-search}+ ;; TODO (BOT-360) enable for :mysql+ (when-not (= :mysql (mdb/db-type))+ (let [crowberto (mt/user->id :crowberto)+ rasta (mt/user->id :rasta)]+ (mt/with-temp [:model/Card {c1 :id} {}+ :model/Card {c2 :id} {}]+ (testing "bookmarked items are ranker higher"+ (with-index-contents!+ [{:model "card" :id c1 :name "card normal"}+ {:model "card" :id c2 :name "card crowberto loved"}]+ (mt/with-temp [:model/CardBookmark _ {:card_id c2 :user_id crowberto}+ :model/CardBookmark _ {:card_id c1 :user_id rasta}]+ (is (= [["card" c2 "card crowberto loved"]+ ["card" c1 "card normal"]]+ (search-results :bookmarked "card" {:current-user-id crowberto})))))))- (mt/with-temp [:model/Dashboard {d1 :id} {}- :model/Dashboard {d2 :id} {}]- (testing "bookmarked dashboard"- (with-index-contents!- [{:model "dashboard" :id d1 :name "dashboard normal"}- {:model "dashboard" :id d2 :name "dashboard crowberto loved"}]- (mt/with-temp [:model/DashboardBookmark _ {:dashboard_id d2 :user_id crowberto}- :model/DashboardBookmark _ {:dashboard_id d1 :user_id rasta}]- (is (= [["dashboard" d2 "dashboard crowberto loved"]- ["dashboard" d1 "dashboard normal"]]- (search-results :bookmarked "dashboard" {:current-user-id crowberto})))))))+ (mt/with-temp [:model/Dashboard {d1 :id} {}+ :model/Dashboard {d2 :id} {}]+ (testing "bookmarked dashboard"+ (with-index-contents!+ [{:model "dashboard" :id d1 :name "dashboard normal"}+ {:model "dashboard" :id d2 :name "dashboard crowberto loved"}]+ (mt/with-temp [:model/DashboardBookmark _ {:dashboard_id d2 :user_id crowberto}+ :model/DashboardBookmark _ {:dashboard_id d1 :user_id rasta}]+ (is (= [["dashboard" d2 "dashboard crowberto loved"]+ ["dashboard" d1 "dashboard normal"]]+ (search-results :bookmarked "dashboard" {:current-user-id crowberto})))))))- (mt/with-temp [:model/Collection {c1 :id} {}- :model/Collection {c2 :id} {}]- (testing "bookmarked collection"- (with-index-contents!- [{:model "collection" :id c1 :name "collection normal"}- {:model "collection" :id c2 :name "collection crowberto loved"}]- (mt/with-temp [:model/CollectionBookmark _ {:collection_id c2 :user_id crowberto}- :model/CollectionBookmark _ {:collection_id c1 :user_id rasta}]- (is (= [["collection" c2 "collection crowberto loved"]- ["collection" c1 "collection normal"]]- (search-results :bookmarked "collection" {:current-user-id crowberto})))))))))+ (mt/with-temp [:model/Collection {c1 :id} {}+ :model/Collection {c2 :id} {}]+ (testing "bookmarked collection"+ (with-index-contents!+ [{:model "collection" :id c1 :name "collection normal"}+ {:model "collection" :id c2 :name "collection crowberto loved"}]+ (mt/with-temp [:model/CollectionBookmark _ {:collection_id c2 :user_id crowberto}+ :model/CollectionBookmark _ {:collection_id c1 :user_id rasta}]+ (is (= [["collection" c2 "collection crowberto loved"]+ ["collection" c1 "collection normal"]]+ (search-results :bookmarked "collection" {:current-user-id crowberto})))))))))))(deftest user-recency-test- (let [user-id (mt/user->id :crowberto)- right-now (Instant/now)- long-ago (.minus right-now 10 ChronoUnit/DAYS)- forever-ago (.minus right-now 30 ChronoUnit/DAYS)- recent-view (fn [model-id timestamp]- {:model "card"- :model_id model-id- :user_id user-id- :timestamp timestamp})]- (mt/with-temp [:model/Card {c1 :id} {}- :model/Card {c2 :id} {}- :model/Card {c3 :id} {}- :model/Card {c4 :id} {}- :model/RecentViews _ (recent-view c1 forever-ago)- :model/RecentViews _ (recent-view c2 right-now)- :model/RecentViews _ (recent-view c2 forever-ago)- :model/RecentViews _ (recent-view c4 forever-ago)- :model/RecentViews _ (recent-view c4 long-ago)]- (with-index-contents!- [{:model "card" :id c1 :name "card ancient"}- {:model "metric" :id c2 :name "card recent"}- {:model "dataset" :id c3 :name "card unseen"}- {:model "dataset" :id c4 :name "card old"}]- (testing "We prefer results more recently viewed by the current user"- (is (= [["metric" c2 "card recent"]- ["dataset" c4 "card old"]- ["card" c1 "card ancient"]- ["dataset" c3 "card unseen"]]- (search-results :user-recency "card" {:current-user-id user-id}))))))))+ (mt/with-premium-features #{:semantic-search}+ ;; TODO (BOT-360) enable for :mysql+ (when-not (= :mysql (mdb/db-type))+ (let [user-id (mt/user->id :crowberto)+ right-now (Instant/now)+ long-ago (.minus right-now 10 ChronoUnit/DAYS)+ forever-ago (.minus right-now 30 ChronoUnit/DAYS)+ recent-view (fn [model-id timestamp]+ {:model "card"+ :model_id model-id+ :user_id user-id+ :timestamp timestamp})]+ (mt/with-temp [:model/Card {c1 :id} {}+ :model/Card {c2 :id} {}+ :model/Card {c3 :id} {}+ :model/Card {c4 :id} {}+ :model/RecentViews _ (recent-view c1 forever-ago)+ :model/RecentViews _ (recent-view c2 right-now)+ :model/RecentViews _ (recent-view c2 forever-ago)+ :model/RecentViews _ (recent-view c4 forever-ago)+ :model/RecentViews _ (recent-view c4 long-ago)]+ (with-index-contents!+ [{:model "card" :id c1 :name "card ancient"}+ {:model "metric" :id c2 :name "card recent"}+ {:model "dataset" :id c3 :name "card unseen"}+ {:model "dataset" :id c4 :name "card old"}]+ (testing "We prefer results more recently viewed by the current user"+ (is (= [["metric" c2 "card recent"]+ ["dataset" c4 "card old"]+ ["card" c1 "card ancient"]+ ["dataset" c3 "card unseen"]]+ (search-results :user-recency "card" {:current-user-id user-id}))))))))))diff --git a/src/metabase/search/in_place/legacy.clj b/src/metabase/search/in_place/legacy.cljindex 1e69593a7dc..b9071028134 100644--- a/src/metabase/search/in_place/legacy.clj+++ b/src/metabase/search/in_place/legacy.clj@@ -608,8 +608,7 @@:limit search.config/*db-max-results*})));; Return a reducible-query corresponding to searching the entities without an index.-(defmethod search.engine/results- :search.engine/in-place+(defn- results[search-ctx](let [search-query (full-search-query search-ctx)](log/tracef "Searching with query:\n%s\n%s"@@ -617,5 +616,10 @@(mdb/format-sql (first (mdb/compile search-query))))(t2/reducible-query search-query)))+(defmethod search.engine/results+ :search.engine/in-place+ [search-ctx]+ (results search-ctx))+(defmethod search.engine/score :search.engine/in-place [search-ctx result](scoring/score-and-result result search-ctx))