This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QUERY_FIELDS = { | |
| title: { types: [:fuzzy] }, | |
| formatted_text: { types: [:word] }, | |
| author: { boost: 3.0, types: [:word] }, # qua definiamo sia il tipo che il boost, solo per questa parola. | |
| abstract_text: { types: [:fuzzy] }, | |
| location: { types: [:infix] }, | |
| technique: { types: [:prefix] }, | |
| }.freeze | |
| def matching_text_scope(text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def word_weight(word) | |
| case word | |
| when "botteghe" | |
| 0.0 | |
| when /\Ab[ao]tte\z/ | |
| 0.0 | |
| else | |
| 1.0 | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mastico::Query.new(fields: [:author], query: "Botticello").apply(chewy_query).load.to_a | |
| => [#<Artwork:0x007fa66e9a78f8 | |
| id: 30, | |
| museum_id: 6, | |
| title: "Adorazione dei Magi" | |
| author: "Sandro Botticelli (Firenze 1445-1510)", | |
| position: 2>, | |
| #<Artwork:0x007fa66e9a7678 | |
| id: 3, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mastico::Query.new(fields: [:title, :author], query: "Venere Botticelli").apply(chewy_query).load.to_a | |
| => [#<Artwork:0x007fa66a4281b0 | |
| id: 3, | |
| museum_id: 15, | |
| title: "Nascita di Venere", | |
| author: "Sandro Botticelli (Firenze 1445-1510) ", | |
| position: 109>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| chewy_query = UffiziIndex::Artwork.all | |
| Mastico::Query.new(fields: [:title], query: "Venere").apply(chewy_query).load.to_a | |
| => [#<Artwork:0x007fa6668fc820 | |
| id: 3, | |
| museum_id: 15, | |
| title: "Nascita di Venere", | |
| author: "Sandro Botticelli (Firenze 1445-1510) ", | |
| position: 109>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UffiziIndex::Artwork.all.query(multi_match: {fields: [:title, :author], query: "venere botticelli"}).load.to_a | |
| => [#<Artwork:0x007fa66eada0b8 | |
| id: 3, | |
| museum_id: 15, | |
| title: "Nascita di Venere", | |
| author: "Sandro Botticelli (Firenze 1445-1510) ", | |
| position: 109>, | |
| #<Artwork:0x007fa66eada360 | |
| id: 30, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UffiziIndex::Artwork.all.query(word: {title: "venere"}).query(word: {author: "botticelli"}).load.to_a | |
| => [#<Artwork:0x007fa66ec00a28 | |
| id: 3, | |
| museum_id: 15, | |
| title: "Nascita di Venere", | |
| author: "Sandro Botticelli (Firenze 1445-1510) ", | |
| position: 109>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UffiziIndex::Artwork.all.query(word: {title: "venere"}).load.to_a | |
| => [#<Artwork:0x007fa66ec00a28 | |
| id: 3, | |
| museum_id: 15, | |
| title: "Nascita di Venere", | |
| author: "Sandro Botticelli (Firenze 1445-1510) ", | |
| position: 109>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UffiziIndex < Chewy::Index | |
| class << self | |
| def index_name(_suggest = nil) | |
| "#{Rails.env}_uffizi_#{I18n.locale}" | |
| end | |
| end | |
| define_type( | |
| Artwork.includes(:museum), | |
| delete_if: -> { translation_for(I18n.locale).nil? } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "body": { | |
| "query": { | |
| "bool": { | |
| "must": [ | |
| { | |
| "bool": { | |
| "should": [ | |
| { | |
| "bool": { |
NewerOlder