-
-
Notifications
You must be signed in to change notification settings - Fork 20
🧹 Journal
: Entries
store their Keywords
#1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Journal
: Entries
may be queried by Keywords
Journal
: Entries
may be queried by Keywords
Journal
: Entries
may be queried by Keywords
Journal
: Entries
store their Keywords
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having keywords at both the Journal and the Entry level feels a little bit overkill to me, but I'm sure you have some larger plan for what that's necessary.
app/furniture/journal/keyword.rb
Outdated
.or(where(canonical_keyword: keyword)).exists? | ||
body.scan(/#(\w+)/)&.flatten&.map do |keyword| | ||
existing_keyword = where(":aliases = ANY (aliases)", aliases: keyword) | ||
.or(where(canonical_keyword: keyword)).first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this query is from before your PR, but reading it over right now it struck me that it feels like it should be a nice little scope, which would help tighten up this entire loop a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree; I would love for this to be a scope!
@@ -0,0 +1,5 @@ | |||
class JournalAddKeywordsToEntries < ActiveRecord::Migration[7.0] | |||
def change | |||
add_column :journal_entries, :keywords, :string, array: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised these are not tied in any way to the ids of the Journal keywords -- I would have expected you'd want that to show "all entries with keyword X in Journal".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I was thinking a join table would be "too much" but I suppose it's not?
The way I was planning to find the Entries
was indexing this keywords field and using the scope you suggested above; but I do worry that that would make the relationy bits a bit less railsy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent too long trying to figure out where the keywords were shown in the UI....
I should read more deeply. 😬
I was thinking that an
I am trying to take very very tiny steps; instead of just YOLO-Shipping the whole thing lol. It does make it a bit harder to figure out the trajectory tho. |
- https://github.com/zinc-collective/convene/issues/1662 - https://github.com/zinc-collective/convene/issues/1566 This gets us a little bit closer to being able to browse `Entry` by `Keyword`s, since each `Entry` will know it's keywords
6f9a625
to
6ffd6bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've extracted the scope; and I am wanting to see how far I can get before sprouting the join table
The reason I'm avoiding the join table is because I work in another code base with hundreds of thousands of "taggings" in a join table; and the performance characteristics are pretty bad; even with fully indexing the taggings table across the tag_id and entry_id in both directions!
My gut says that storing the tags an Entry uses and indexing that will be far more performant because using the canonical keyword as a kind of "natural join" when traversing from the keyword to the entries; and from the entries to the keywords.
But I'm willing to drop that concern.
@@ -6,10 +6,16 @@ class Keyword < ApplicationRecord | |||
validates :canonical_keyword, presence: true, uniqueness: {case_sensitive: false, scope: :journal_id} | |||
belongs_to :journal, inverse_of: :keywords | |||
|
|||
scope(:search, lambda do |*keywords| | |||
where("lower(aliases::text)::text[] && ARRAY[?]::text[]", keywords.map(&:downcase)) | |||
.or(where("lower(canonical_keyword) IN (?)", keywords.map(&:downcase))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a way less awkward way of doing this; but this is what I was able to come up with 🙃
Journal
: BrowsingEntries
journal#4Journal
: WritingEntries
journal#2This gets us a little bit closer to being able to browse
Entry
byKeyword
s, since eachEntry
will know it's keywords