From 2cf1396e3ccec7a5f19c8c1862aa3c795b1b3c05 Mon Sep 17 00:00:00 2001 From: David Pan <12668+davidpan@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:54:26 +0800 Subject: [PATCH 1/3] add Define fields to search on at search-time --- .code-samples.meilisearch.yaml | 5 ++++ README.md | 28 +++++++++++++++++++ lib/meilisearch/index.rb | 4 +++ spec/meilisearch/index/search/q_spec.rb | 37 +++++++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index e1cdb85e..c6408106 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -335,6 +335,11 @@ search_parameter_guide_matching_strategy_2: |- client.index('movies').search('big fat liar', { matching_strategy: 'all' }) +search_parameter_guide_attributes_to_search_on_1: |- + POST 'http://localhost:7700/indexes/movies/search' + with data: { + "q": "adventure", "attributesToSearchOn": ["overview"] + } add_movies_json_1: |- require 'json' diff --git a/README.md b/README.md index f66a89b3..9ec0ed29 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,34 @@ JSON output: } ``` +#### Custom Search With attributes on at search time + +[Customize attributes to search on at search time](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time). + +Available ONLY with Meilisearch v1.3 and newer (optional). + + +you can perform the search : + +```ruby +index.search('wonder', { attributes_to_search_on: ['genres'] }) +``` + + +JSON output: + +```json +{ + "hits":[], + "query":"wonder", + "processingTimeMs":0, + "limit":20, + "offset":0, + "estimatedTotalHits":0, + "nbHits":0 +} +``` + ## 🤖 Compatibility with Meilisearch This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info. diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index ccd4def9..c5df3050 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -220,6 +220,10 @@ def delete_all_documents! ### SEARCH + # option: + # attributes_to_search_on: Customize attributes to search on at search time. + # Available ONLY with Meilisearch v1.3 and newer (optional). + def search(query, options = {}) attributes = { q: query.to_s }.merge(options.compact) diff --git a/spec/meilisearch/index/search/q_spec.rb b/spec/meilisearch/index/search/q_spec.rb index bea94f75..3c7e5e0a 100644 --- a/spec/meilisearch/index/search/q_spec.rb +++ b/spec/meilisearch/index/search/q_spec.rb @@ -83,4 +83,41 @@ expect(response.keys).to contain_exactly(*FINITE_PAGINATED_SEARCH_RESPONSE_KEYS) end end + + context 'with attributes_to_search_on params' do + it 'responds with empty attributes_to_search_on' do + response = index.search('prince', { attributes_to_search_on: [] }) + expect(response).to be_a(Hash) + expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS) + expect(response['hits']).to be_empty + end + + it 'responds with nil attributes_to_search_on' do + response = index.search('prince', { attributes_to_search_on: nil }) + expect(response).to be_a(Hash) + expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS) + expect(response['hits']).not_to be_empty + end + + it 'responds with title attributes_to_search_on' do + response = index.search('prince', { attributes_to_search_on: ['title'] }) + expect(response).to be_a(Hash) + expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS) + expect(response['hits']).not_to be_empty + end + + it 'responds with genre attributes_to_search_on' do + response = index.search('prince', { attributes_to_search_on: ['genry'] }) + expect(response).to be_a(Hash) + expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS) + expect(response['hits']).to be_empty + end + + it 'responds with nil attributes_to_search_on and empty query' do + response = index.search('', { attributes_to_search_on: nil }) + expect(response).to be_a(Hash) + expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS) + expect(response['hits'].count).to eq(documents.count) + end + end end From 9caa561fb019f5726248793da6e44daa8d6bbd43 Mon Sep 17 00:00:00 2001 From: David Pan <12668+davidpan@users.noreply.github.com> Date: Tue, 22 Aug 2023 09:16:34 +0800 Subject: [PATCH 2/3] merge readme fix. --- README.md | 78 +------------------------------------------------------ 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/README.md b/README.md index 05d76de2..c7429813 100644 --- a/README.md +++ b/README.md @@ -207,34 +207,6 @@ JSON output: } ``` -#### Custom Search With attributes on at search time - -[Customize attributes to search on at search time](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time). - -Available ONLY with Meilisearch v1.3 and newer (optional). - - -you can perform the search : - -```ruby -index.search('wonder', { attributes_to_search_on: ['genres'] }) -``` - - -JSON output: - -```json -{ - "hits":[], - "query":"wonder", - "processingTimeMs":0, - "limit":20, - "offset":0, - "estimatedTotalHits":0, - "nbHits":0 -} -``` - #### Display ranking details at search JSON output: @@ -287,9 +259,6 @@ This feature is only available with Meilisearch v1.3 and newer (optional). [Customize attributes to search on at search time](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time). -Available ONLY with Meilisearch v1.3 and newer (optional). - - you can perform the search : ```ruby @@ -311,54 +280,9 @@ JSON output: } ``` -#### Display ranking details at search - -JSON output: - -```json -{ - "hits": [ - { - "id": 15359, - "title": "Wonder Woman", - "_rankingScoreDetails": { - "words": { - "order": 0, - "matchingWords": 2, - "maxMatchingWords": 2, - "score": 1.0 - }, - "typo": { - "order": 1, - "typoCount": 0, - "maxTypoCount": 2, - "score": 1.0 - }, - "proximity": { - "order": 2, - "score": 1.0 - }, - "attribute": { - "order": 3, - "attributeRankingOrderScore": 0.8181818181818182, - "queryWordDistanceScore": 1.0, - "score": 0.8181818181818182 - }, - "exactness": { - "order": 4, - "matchType": "exactMatch", - "score": 1.0 - } - } - } - ] -} -``` - -You can enable it by querying PATCH /experimental-features with { "scoreDetails": true } - This feature is only available with Meilisearch v1.3 and newer (optional). + ## 🤖 Compatibility with Meilisearch This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info. From 2f15d04c653304880648b0ad5041538fe8b6cae5 Mon Sep 17 00:00:00 2001 From: David Pan <12668+davidpan@users.noreply.github.com> Date: Fri, 1 Sep 2023 08:48:24 +0800 Subject: [PATCH 3/3] Update lib/meilisearch/index.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André <1729839+andre-m-dev@users.noreply.github.com> --- lib/meilisearch/index.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 776c5d8c..ea39c77c 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -221,10 +221,8 @@ def delete_all_documents! ### SEARCH # options: A Hash - # show_ranking_score - To see the ranking scores for returned documents - # attributes_to_search_on: Customize attributes to search on at search time. - # Available ONLY with Meilisearch v1.3 and newer (optional). - + # show_ranking_score - To see the ranking scores for returned documents + # attributes_to_search_on - Customize attributes to search on at search time. def search(query, options = {}) attributes = { q: query.to_s }.merge(options.compact)