Matias Fernandez

Joined

5,370 Experience
51 Lessons Completed
0 Questions Solved

Activity

I have a couple of questions about implementing Searchkick and ElasticSearch in general.

  • Let's say I'm using ElasticSearch to search for products like so:

    # usage
    Product.search "apples", fields: [:name]
    -
    # model
    class Product < ApplicationRecord
        searchkick, searchable: [:name], filterable: []
    
        def search_data
            {
                name: name
            }
        end
    end
    

    I don't search by name in any other case (no ActiveRecord queries). Should I remove the table index I have on the name column? (as seen below)

    # remove this?
    add_index :products, :name
    
  • Follow up question: If I'm feeding data to the ElasticSearch server from my database, will indexing (in my db) the search_data fields impact how efficient the Product.reindex function will be? For example:

    # if I have this in my Product model:
    # (It tells ElasticSearch to only reindex the name attribute)
    def search_data
    {
        name: name
    }
    end
    -
    # Does the index by name below impact the reindexing process's speed?
    # If so, is it worth it?
    add_index :products, :name
    
  • Lastly, could Searchkick be the mechanism I use to query most of my data? When is it not recommended to use ElasticSearch? What are some drawbacks, other than losing ActiveRecord functionallity? It seems like it wouldn't be too complicated to add searchkick to mostly all your models and query everything like that.

Thanks in advance for the help! <3

Posted in iTunes Controller Code Review: Part 3 Discussion

These refactoring series are great. Thanks for taking us through it. Any plans on sharing the source?

Thanks Francisco! I corrected the typo.

This works Jacob, thank you for taking the time to help me out. If you want to see it in production, take a look at YugiDecks in the coming weeks.

I've prepared an example on github with seed data and expected results: https://github.com/MatiasFMolinari/example_deck_builder

Requirements and expected results are in the index page.

To summarize, I need to create a scope in the Deck model that only returns the decks that that user can build. It cannot return an enumerable since I need to be able to chain it with other scopes.

I'm making a deck building site similar to hearthpwn.com. It would be nice if users could filter decks based off the cards they have in their inventory.

In other words, I'm trying to make a query that gets the following:

  • All Decks where DeckCard.card_ids are all in UserCard.card_ids AND where deck_card.quantity is less than or equal to the matching user_card.quanitity.

I want to have a scope in the Deck Model that does this. You can see my current implementation below. See scope :with_all_deck_cards_in_user_cards. It doesn't filter the quantities correctly and I need some help debugging it.

Models

class Card
    has_many :user_cards
    has_many :users, through: :user_cards
    has_many :deck_cards
    has_many :decks, through: :deck_cards
end

class User
    has_many :decks
    has_many :user_cards
    has_many :cards, through: :user_cards
end

class Deck
    belongs_to :user
    has_many :deck_cards
    has_many :cards, through: :deck_cards

    user_id

    scope :with_all_deck_cards_in_user_cards, lambda { |user_id|
        user_cards = User.find(user_id).user_cards
        deck_cards = DeckCard.arel_table
        decks      = Deck.arel_table

        user_cards.reduce(self) do |deck, user_card|
            deck.where(
                DeckCard \
                .where(deck_cards[:deck_id].eq(decks[:id])) \
                .where(deck_cards[:card_id].eq(user_card.card_id)) \
                .where(deck_cards[:quantity].lteq(user_card.quantity)) \
                .exists
            )
        end
    }
end

class UserCard
    belongs_to :user
    belongs_to :card

    card_id
    user_id
    quantity
end

class DeckCard
    belongs_to :deck
    belongs_to :card

    card_id
    deck_id
    quantity
end

Let me know if you need any more information.

Posted in Our First API (Example) - GoRails

I'm really excited for this. Awesome job! I love how you gradually introduce topics.

Posted in How to build REST APIs?

I'm really looking forward to this one Chris! I've always wanted to learn how to build an API-only Rails app. From what I understand Rails 5 aims to make this easier than before.

Posted in Inviting Users with devise_invitable Discussion

What made you laugh at 7:25? Is that a bird?! When do we get meet her/him? :)

Perfect, I'll give it a try. Yeah, the project's been a blast! Couldn't have built it without your help!

Here's a preview of how the site is going:

http://www.drinklist.io/

I actually have ElasticSearch already so geosearch might be the way to go. Thanks man.

I'm building an app similar to Yelp. The user should have a current location (taken automatically) and a chosen location (defaulted to current location). Each place should also have a location. I would then take the difference between both the chosen location and the place location to get the distance. Then filter results based on distance. I don't really need more functionality than that.

I've researched some tools that might help such as Google Map's JS API and Ruby Geocoder, but I'm curious how you guys would tackle this.

And just like that, all my troubles disappear. Thanks man!

Posted in Setup MacOS 10.10 Yosemite Discussion

Perfect! Thanks for the tip!

Posted in Setup MacOS 10.10 Yosemite Discussion

Is it normal to have Ruby version different to RubyGems version? Here's a screenshot of what I'm talking about: