Perl 6 - the future is here, just unevenly distributed

IRC log for #askriba, 2017-12-12

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
02:57 ilbot2 joined #askriba
02:57 Topic for #askriba is now Where random Perl5-related questions get definitive answers. Conversation log: https://is.gd/askriba_irclog (searchable). Currently no preset business hours due to low demand: just highlight my name and I'll answer ASAP \o/
07:11 karjala_ joined #askriba
14:49 karjala_ joined #askriba
14:49 karjala_ Hi!
14:49 karjala_ ribasushi,
14:49 karjala_ I need your help, because I have a difficult task!
14:49 karjala_ Would you happen to be around?
15:00 karjala_ Here's my problem:
15:00 karjala_ I developed a webapp that used InnoDB's FULLTEXT feature
15:01 karjala_ It turns out, though, that our production DB is not new enough to ahve InnoDB FULLTEXT index
15:01 karjala_ have*
15:01 karjala_ So I need to do something to adapt
15:02 karjala_ The good thing is that all the search functionality in my app is encapsulated in a single RS method, that is used like this:
15:02 karjala_ $rs->fulltext_query($q)->all
15:02 karjala_ the method is fulltext_query
15:02 karjala_ so all I need to do is replace fulltext_query!
15:02 karjala_ isn't that great?
15:03 karjala_ The question remains: replace it with what?
15:03 karjala_ Well, since the tables to be searched are small (< 1k rows each)
15:04 karjala_ I was thinking that maybe I could write a method that takes an $rs that reads all of the records, processes them with Pure Perl regexes, and outputs a new $rs
15:04 karjala_ I think that looks like a good idea, but what do you think?
15:04 karjala_ The question remains How to do this:
15:05 karjala_ Well, I was thinking that the perl method could do:
15:06 karjala_ my @rows = $self->all; my @row_ids = map grep @rows; return $TABLE->search({id => \@row_ids});
15:06 karjala_ what do you think about my solution?
15:06 karjala_ is it good? is there any better way?
15:06 karjala_ One problem I see is how to inject a custom "score" (search score) in the new resultset
16:41 ashimema interesting problem.. will be interested to see others take.. I have no idea what I'd do myself.
17:05 ribasushi karjala: let me see if I am understanding this right
17:05 karjala_ joined #askriba
17:06 ribasushi karjala_: let me see if I am understanding this right
17:06 karjala_ hi
17:06 ribasushi you have code you have written which relies on being able to execute a FTS wthin the RDBMS and give you a nice DBIC resultset and go on with that
17:06 karjala_ yes
17:07 ribasushi but your prod env does not support FTS and you want to make minimal changes, keeping the resultset codepath
17:07 ribasushi ?
17:07 karjala_ Exactly!
17:08 ribasushi my @filtered_rows = grep { filter them somehow } ( get them somehow )
17:08 ribasushi $rs->set_cache( \@filtered_rows )
17:08 ribasushi use $rs as you'd otherwise
17:08 karjala_ :D
17:08 karjala_ Thanks for the great answer! I will test it tomorrow at work though, can't answer now.
17:09 karjala_ But just out of curiosity, what if I wanted to do $rs->delete? (I don't, but what if?) Would that still work?
17:09 ribasushi that would work ( and do what you expect, badly )
17:09 ribasushi if you want to guard against it:
17:10 ribasushi my $rs = $schema->resultset("whateverthename")->search(\1=0
17:10 ribasushi my $rs = $schema->resultset("whateverthename")->search(\'1=0');  $rs->set_cache([ ... ]);
17:10 ribasushi ^^ $rs->delete/update will fail
17:10 karjala_ a :-)
17:10 ribasushi $rs->next/->all/->reset will continue working as you expect
17:11 karjala_ otherwise it would delete only the rows that it had in the cache?
17:11 ribasushi errr they won't "fail", they will be noops
17:11 ribasushi no it would delete your entire table
17:11 karjala_ thanks!! :D
17:11 karjala_ oh
17:11 ribasushi it's be an unconstrained $rs
17:11 karjala_ Do you have an opinion on which cryptocurrency to buy?
17:11 karjala_ :)
17:12 karjala_ sorry for the Q
17:12 karjala_ ignore it
17:12 ribasushi I will ;)
17:17 karjala_ one more question, ribasushi...
17:18 karjala_ Perl will calculate a "search_score" for every one of the rows... That should be as simple to inject in the rows, as doing: '+columns' => {...}, and then...?
17:18 karjala_ is there a set_column method?
17:19 karjala_ yes there is
17:19 karjala_ ok, i think i've got it
17:19 karjala_ danke
17:20 ribasushi that actually won't work for you
17:20 ribasushi you'll have to create an extra accessor as described here:
17:21 ribasushi http://search.cpan.org/~ribasushi/DBIx-Class-0.082840/lib/DBIx/Class/Manual/FAQ.pod#Misc
17:21 ribasushi the get/set_column is strictly for stuff that took place during the inflation-from-rdbms cycle
17:22 karjala_ ok
17:28 karjala_ and would you suggest the mk_group_accessors method instead of the Moose method, from the page you linked?
17:28 karjala_ ribasushi, ^^
17:28 ribasushi yeah mk_group_accessors( simple => 'search_score' )
17:30 karjala_ (y)
17:32 ribasushi I have to run, hope everything works out for you tomorrow &
17:32 karjala_ thx
17:34 karjala_ I can't then: $rs->prefetch('my_related')->all, though, can I?
17:34 karjala_ efficiently
17:35 karjala_ I'll check
18:04 karjala_ np. Ok, I'll prefetch before calling the ->fulltext_search($q) method, if there's no other way
18:06 karjala_ unless... unless I can somehow store the "scores hash" ('id' => $score_of_id) as an attribute of the $rs somehow... and use that data later to extract the score in the $row->search_score method
18:07 karjala_ So, in that respect, I'm wondering whether it's possible for a $row to retrieve the $rs object it directly came from
18:08 karjala_ Probly wouldn't work, for 100 reasons, I know
19:00 Ya_ALLAH_Ya_Muhmd joined #askriba
19:00 Ya_ALLAH_Ya_Muhmd left #askriba
20:03 Ya_ALLAH_Ya_Muhmd joined #askriba
20:03 Ya_ALLAH_Ya_Muhmd left #askriba
20:25 Ya_ALLAH_Ya_Muhmd joined #askriba
20:25 Ya_ALLAH_Ya_Muhmd left #askriba
21:06 karjala_ joined #askriba
21:11 frew joined #askriba

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary