wip on core side of content management

This commit is contained in:
Zlatin Balevsky
2019-07-09 17:13:09 +01:00
parent 8bbc61a7cb
commit 239d8f12a7
5 changed files with 65 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
package com.muwire.core.content
import com.muwire.core.Event
class ContentControlEvent extends Event {
String term
boolean regex
boolean add
}

View File

@@ -0,0 +1,30 @@
package com.muwire.core.content
import java.util.concurrent.ConcurrentHashMap
import com.muwire.core.search.QueryEvent
import net.i2p.util.ConcurrentHashSet
class ContentManager {
Set<Matcher> matchers = new ConcurrentHashSet()
void onContentControlEvent(ContentControlEvent e) {
Matcher m
if (e.regex)
m = new RegexMatcher(e.term)
else
m = new KeywordMatcher(e.term)
if (e.add)
matchers.add(m)
else
matchers.remove(m)
}
void onQueryEvent(QueryEvent e) {
if (e.searchEvent.searchTerms == null)
return
matchers.each { it.process(e) }
}
}

View File

@@ -14,4 +14,17 @@ class KeywordMatcher extends Matcher {
}
false
}
@Override
public int hashCode() {
keyword.hashCode()
}
@Override
public boolean equals(Object o) {
if (!(o instanceof KeywordMatcher))
return false
KeywordMatcher other = (KeywordMatcher) o
keyword.equals(other.keyword)
}
}

View File

@@ -9,8 +9,6 @@ abstract class Matcher {
public void process(QueryEvent qe) {
def terms = qe.searchEvent.searchTerms
if (terms == null)
return
if (match(terms)) {
long now = System.currentTimeMillis()
matches << new Match(persona : qe.originator, keywords : terms, timestamp : now)

View File

@@ -14,4 +14,17 @@ class RegexMatcher extends Matcher {
String combined = keywords.join(" ")
return pattern.matcher(combined).find()
}
@Override
public int hashCode() {
pattern.hashCode()
}
@Override
public boolean equals(Object o) {
if (!(o instanceof RegexMatcher))
return false
RegexMatcher other = (RegexMatcher) o
pattern.equals(other.pattern)
}
}