Comments (15)
Yeah, currently there is no way to do it. Indexing objects with parent is not supported for now. I need to dig deeper to figure out how to do this.
Currently I think it should be like this:
define_type Column.includes(:table) do
root _parent: { type: 'table' }, parent: -> { table.id } do
field ...
end
end
Or maybe use parent_id
key instead of just parent
to define parent id evaluator proc
from chewy.
Okay, I may work on this but for now it'd be nice to have a work-around for my use case. Basically there is a field in the parent that is expensive to calculate and is also needed for each of its children. If I could store results for this expensive function in a hash at index time then I could just look up in the hash instead of having to recalculate for each child.
I tried doing something like this but just getting Nil
for the @table_permissions_store
.
@table_permissions_store = TablePermissionsStore.new()
define_type Table do
field :_id, type: 'integer', value: { id }
field :user_ids, value: -> { @table_permissions_store.get_permission(self) }
end
define_type Column.includes(:table) do
field :user_ids, value: -> { @table_permissions_store.get_permission(table) }
end
Is there any way to do something like this?
from chewy.
Yeah, sure, because value procs are called in the AR object context. Try value: -> (table) { @table_permissions_store.get_permission(table) }
At this case the context of value proc should not be changed. But I'm still not sure you need this. It seems like TablePermissionsStore object will be initialized only once on the application start. If this is what you need - it is better to use constant, it will be available from every context. If this is not - then explain what are you trying to do. Maybe it is a new object for every stored record?
from chewy.
Sorry, it is just a hash that stores permissions at index time. If the key for a specific table is already in the hash then it just does a lookup and the value at that key is the permission. If the key isn't there then it runs the expensive function to get the user permissions and stores it in the hash.
So anytime a new index action is occurring (specifically reset and import), the hash should be reset to be empty (since permissions can change). Maybe I can use the chewy atomic block?
from chewy.
I'm still thinking about how to implement such a case. Previous code will not work, I'm sure. But Don't even know. Maybe you have to redefine import method for index? To initialize TablePermissionsStore, but how to access it inside importer? Maybe use a kind of https://github.com/pyromaniac/contextuality to create variable inside the import context. Not sure.
from chewy.
Okay, it seems like a work around will be pretty difficult so I'm just going to work on adding in parent/child mappings.
from chewy.
https://gist.github.com/baothi/72c63fbb9b8b4675188e
please help me error
from chewy.
just place tcos_index.rb
inside app/chewy
dir and pay attention to it's name
from chewy.
hi pyromaniac
yes I do same gem chewy but It until error
from chewy.
are you sure your file named tacos_index.rb
?
from chewy.
https://www.youtube.com/watch?v=v_MCcue2uEA
yes i see here
from chewy.
hi pyromaniac
have you skype, you can add my skype help me
my skype: bao.thi2
from chewy.
just try to execute spring stop
in bash and do rails c
once again
from chewy.
hi pyromaniac
yes i try ``spring stop` but it still error
from chewy.
hi pyromaniac
when i do again bin/spring stop it run TacosIndex
but when i run TacosIndex::Taco.import(Taco.all)
it error Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200
from chewy.
Related Issues (20)
- Cleanup journal throws `Yajl::EncodeError: Max nesting depth of 256 exceeded`
- Old indices are not being cleared up after a reset
- Port PR #874 to the 7.0.x branch
- Trying to use Pagy pagination with Chewy, running into autoloading will_paginate gem
- Breaking change at 7.2.4
- I have a question regarding elasticsearch-ruby gem
- Support rails parallel testing HOT 1
- Warning when upgrading to Rails 7.1
- "#<Chewy::UndefinedUpdateStrategy: Index update strategy is undefined for current context.\n Please wrap your code with `Chewy.strategy(:strategy_name) block.`\n>"} HOT 3
- Update Index Derived from Multiple Associated Models
- Index#order - add missing first/last option
- Deprecated the `zrangebyscore` command
- How to migrate to chewy 7.2 HOT 1
- can not use import to delete missings source objects
- Rake chewy:sync should work for complex "outdated_sync_field" values HOT 2
- Use ENV variable to name index by default HOT 1
- Run some code after indexing has completed
- Status of indexes
- Add inner_hits DSL
- Closing open connections to Elasticsearch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chewy.