projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add Sone change collector
[Sone.git]
/
src
/
main
/
kotlin
/
net
/
pterodactylus
/
sone
/
web
/
pages
/
SearchPage.kt
diff --git
a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt
b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt
index
e94d879
..
76c2341
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt
@@
-98,22
+98,19
@@
class SearchPage(template: Template, webInterface: WebInterface, ticker: Ticker
.filter { PostReply.FUTURE_REPLY_FILTER.apply(it) }
.map { "${soneNameCache(it.sone)} ${it.text}" }.joinToString(" ", " ")).toLowerCase()
.filter { PostReply.FUTURE_REPLY_FILTER.apply(it) }
.map { "${soneNameCache(it.sone)} ${it.text}" }.joinToString(" ", " ")).toLowerCase()
+ private fun Iterable<Phrase>.indicesFor(text: String, predicate: (Phrase) -> Boolean) =
+ filter(predicate).map(Phrase::phrase).map(String::toLowerCase).flatMap { text.findAll(it) }
+
private fun score(text: String, phrases: Iterable<Phrase>): Double {
val requiredPhrases = phrases.count { it.required }
private fun score(text: String, phrases: Iterable<Phrase>): Double {
val requiredPhrases = phrases.count { it.required }
- val requiredHits = phrases.filter(Phrase::required)
- .map(Phrase::phrase)
- .flatMap { text.findAll(it) }
+ val requiredHits = phrases.indicesFor(text, Phrase::required)
.map { Math.pow(1 - it / text.length.toDouble(), 2.0) }
.sum()
.map { Math.pow(1 - it / text.length.toDouble(), 2.0) }
.sum()
- val optionalHits = phrases.filter(Phrase::optional)
- .map(Phrase::phrase)
- .flatMap { text.findAll(it) }
+ val optionalHits = phrases.indicesFor(text, Phrase::optional)
.map { Math.pow(1 - it / text.length.toDouble(), 2.0) }
.sum()
.map { Math.pow(1 - it / text.length.toDouble(), 2.0) }
.sum()
- val forbiddenHits = phrases.filter(Phrase::forbidden)
- .map(Phrase::phrase)
- .map { text.findAll(it).size }
- .sum()
+ val forbiddenHits = phrases.indicesFor(text, Phrase::forbidden)
+ .count()
return requiredHits * 3 + optionalHits + (requiredHits - requiredPhrases) * 5 - (forbiddenHits * 2)
}
return requiredHits * 3 + optionalHits + (requiredHits - requiredPhrases) * 5 - (forbiddenHits * 2)
}
@@
-126,7
+123,6
@@
class SearchPage(template: Template, webInterface: WebInterface, ticker: Ticker
private fun String.parse() =
StringEscaper.parseLine(this)
private fun String.parse() =
StringEscaper.parseLine(this)
- .map(String::toLowerCase)
.map {
when {
it == "+" || it == "-" -> Phrase(it, OPTIONAL)
.map {
when {
it == "+" || it == "-" -> Phrase(it, OPTIONAL)