make forum search aware of troll isolation
This commit is contained in:
parent
839e2dc163
commit
e0bd8adc42
|
@ -8,7 +8,7 @@ object ForumPost extends LilaController with ForumController {
|
|||
def search(text: String, page: Int) = OpenBody { implicit ctx ⇒
|
||||
text.trim.isEmpty.fold(
|
||||
Redirect(routes.ForumCateg.index).fuccess,
|
||||
Env.forumSearch(text, page, isGranted(_.StaffForum)) map { paginator ⇒
|
||||
Env.forumSearch(text, page, isGranted(_.StaffForum), ctx.troll) map { paginator ⇒
|
||||
html.forum.search(text, paginator)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -20,8 +20,8 @@ final class Env(
|
|||
private val PaginatorMaxPerPage = config getInt "paginator.max_per_page"
|
||||
private val IndexerName = config getString "indexer.name"
|
||||
|
||||
def apply(text: String, page: Int, staff: Boolean) =
|
||||
paginatorBuilder(Query(text, staff), page)
|
||||
def apply(text: String, page: Int, staff: Boolean, troll: Boolean) =
|
||||
paginatorBuilder(Query(text, staff, troll), page)
|
||||
|
||||
private lazy val indexer: ActorRef = system.actorOf(Props(new Indexer(
|
||||
lowLevel = lowLevelIndexer,
|
||||
|
|
|
@ -12,6 +12,7 @@ private[forumSearch] object Post {
|
|||
val topicId = "ti"
|
||||
val author = "au"
|
||||
val staff = "st"
|
||||
val troll = "tr"
|
||||
}
|
||||
import fields._
|
||||
import ElasticSearch.Mapping._
|
||||
|
@ -22,7 +23,8 @@ private[forumSearch] object Post {
|
|||
boost(topic, "string", 4),
|
||||
boost(author, "string"),
|
||||
field(topicId, "string"),
|
||||
field(staff, "boolean")
|
||||
field(staff, "boolean"),
|
||||
field(troll, "boolean")
|
||||
).toMap),
|
||||
"analyzer" -> "snowball"
|
||||
)
|
||||
|
@ -32,6 +34,7 @@ private[forumSearch] object Post {
|
|||
topic -> view.topic.name,
|
||||
author -> ~(view.post.userId orElse view.post.author),
|
||||
topicId -> view.topic.id,
|
||||
staff -> view.post.isStaff
|
||||
staff -> view.post.isStaff,
|
||||
troll -> view.post.troll
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import Post.fields
|
|||
import org.elasticsearch.index.query._, QueryBuilders._, FilterBuilders._
|
||||
|
||||
private[forumSearch] final class Query private (
|
||||
terms: List[String], staff: Boolean) extends lila.search.Query {
|
||||
terms: List[String],
|
||||
staff: Boolean,
|
||||
troll: Boolean) extends lila.search.Query {
|
||||
|
||||
def searchRequest(from: Int = 0, size: Int = 10) = ElasticSearch.Request.Search(
|
||||
query = makeQuery,
|
||||
|
@ -22,12 +24,15 @@ private[forumSearch] final class Query private (
|
|||
}
|
||||
}
|
||||
|
||||
private def makeFilters = !staff option termFilter(fields.staff, false)
|
||||
private def makeFilters = List(
|
||||
!staff option termFilter(fields.staff, false),
|
||||
!troll option termFilter(fields.troll, false)
|
||||
).flatten.toNel map { fs ⇒ andFilter(fs.list: _*) }
|
||||
}
|
||||
|
||||
object Query {
|
||||
|
||||
def apply(text: String, staff: Boolean): Query = new Query(
|
||||
ElasticSearch.Request decomposeTextQuery text, staff
|
||||
def apply(text: String, staff: Boolean, troll: Boolean): Query = new Query(
|
||||
ElasticSearch.Request decomposeTextQuery text, staff, troll
|
||||
)
|
||||
}
|
||||
|
|
|
@ -64,9 +64,7 @@ case class Query(
|
|||
toFilters(rated, fields.rated),
|
||||
toFilters(opening, fields.opening),
|
||||
toFilters(status, fields.status)
|
||||
).flatten.toNel map { fs ⇒
|
||||
andFilter(fs.list: _*)
|
||||
}
|
||||
).flatten.toNel map { fs ⇒ andFilter(fs.list: _*) }
|
||||
|
||||
private def hasAiFilters = hasAi.toList map { a ⇒
|
||||
a.fold(existsFilter(fields.ai), missingFilter(fields.ai))
|
||||
|
|
Loading…
Reference in a new issue