Closed umputun closed 5 years ago
Some questions regarding this issue:
abc*
, *bcd*
, *xyz
, a?cd
?The simplest solution looks like:
simplest sounds good, just a few details:
store.service
package because it will be used by create and edit func. Another possible place is rest_private, but service feels like a better choice for me.Lister
interface with some List(siteID string) (restricted []string, err error)
and Matcher
struct accepting comment and returns a bool. Obviously Lister
will be injected into Matcher
Type
in cmd.ServerCommand
, similar to other option groups we already have@amelnikov-mylivn is this something you planning to implement?
@umputun Yes. I planned it for this weekend. Last weekend was surprisingly busy.
I just want to check with you about interfaces and component layout before I go deeper. I created interfaces and naive implementations for some classes (I plan to add other implementations f.e. for Matcher). Can you please check this branch https://github.com/umputun/remark/compare/master...amelnikov-mylivn:feature-support-restricted-words ?
I have 4 interfaces right now:
Tokenizer
- extracts words from raw textMatcher
- matches words from comments against restricted wordsLister
- returns raw list of words for specified siteIDChecker
- uses all above interfaces inside to check comment text against restricted words for specified siteID. Note matcherFactory
(got better name? this is so javish). It exists because: a) creation of Matcher usually involves constructing some underlying datastructure and we do not want to create it each time we want to check a comment; b) there can be more than one implementation.This is how we can construct the checker:
NewRestrictedWordsChecker(WhitespaceTokenizer{}, SimpleLister{restrictedWords}, func(words []string) Matcher {
return NewSimpleMatcher(words)
})
If you have any suggestions or critics about code style I would also like to hear them.
A couple of things:
service.Matcher{Lister: store.StaticLister{Words: opts.Restricted.Static.Words}
If someday we need to customize checker or tokenizer we could do it by introducing interface or functional argument, but for now, we have no such need
Tokenizer
, Matcher
and Checker
into a single struct Matcher
that will have just a single public method Match(siteID string, text string) bool
?yes
This pull request https://github.com/umputun/remark/pull/257 is just a followup of our discussion - not a final version
I think I finished simple implementation of this feature. Just to be on the same page - I wanted to try to add matching that allows to specify restricted words with masks like abc*
, *bcd*
, *xyz
, a?cd
. Is it something useful for the project or you think simple equals matching is good enough?
Thx again. I have reordered Match
a little bit to eliminate potentially unnecessary tokenize
call if the list empty or can't be loaded.
The goal is to allow a list of filtered words to be defined and passed in. Attempt to post a comment with those words will be rejected.