Giter VIP home page Giter VIP logo

Comments (5)

ankane avatar ankane commented on July 16, 2024

There's no way to do this right now. The best way (in your simple example) would be to change search data to:

def search_data
  as_json(only: [:title, :created_at]).merge(user_id: user.id)
end

The ability to query nested documents would be nice as long as it's simple. I'm going to remove the nested example from the readme for now.

from searchkick.

masonoise avatar masonoise commented on July 16, 2024

Right, I thought that the merging could do it, but I'd be doing it for a number of associated model properties. It might be okay, so I'll try that out. Handling associations would be a great addition later. Thanks.

from searchkick.

masonoise avatar masonoise commented on July 16, 2024

Ah, and I forgot the other issue, which is that I'm dealing with a set of associated objects, which gets trickier of course. For example, if I have Items and each Item has many Users, and I need to be able to search for all of the Items with name "Foo" that are associated with a specific user. It's not well-suited for the merge solution. Thanks again.

from searchkick.

ankane avatar ankane commented on July 16, 2024

While you can't search nested attributes, you can search arrays.

class Item
  def search_data
    {user_ids: users.pluck(:id)}
  end
end

And

Item.search "Foo", where: {user_ids: 1}

Hopefully that helps with your last comment.

from searchkick.

ankane avatar ankane commented on July 16, 2024

Created a new issue for nested queries #145

from searchkick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.