Skip to content

Commit

Permalink
еще косяк с датами в индексе
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcom committed Jul 30, 2024
1 parent fa174fa commit 7fe814e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions src/main/scala/ru/org/linux/search/SearchResultService.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1998-2023 Linux.org.ru
* Copyright 1998-2024 Linux.org.ru
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -17,10 +17,8 @@ package ru.org.linux.search

import com.sksamuel.elastic4s.requests.searches.SearchHit
import com.sksamuel.elastic4s.requests.searches.aggs.responses.{Aggregations, FilterAggregationResult}
import com.sksamuel.elastic4s.requests.searches.aggs.responses.bucket.TermBucket
import com.sksamuel.elastic4s.requests.searches.aggs.responses.bucket.{TermBucket, Terms}
import com.typesafe.scalalogging.StrictLogging
import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
import org.springframework.stereotype.Service
import org.springframework.web.util.UriComponentsBuilder
import ru.org.linux.group.GroupDao
Expand All @@ -30,19 +28,19 @@ import ru.org.linux.user.{User, UserService}
import ru.org.linux.util.StringUtil

import java.time.Instant
import java.util.Date
import scala.beans.BeanProperty
import scala.jdk.CollectionConverters.*

case class SearchItem (
@BeanProperty title: String,
@BeanProperty postdate: DateTime,
@BeanProperty user: User, // TODO use UserRef
@BeanProperty postdate: Date,
@BeanProperty user: User,
@BeanProperty message: String,
@BeanProperty url: String,
@BeanProperty score: Float,
@BeanProperty comment: Boolean,
@BeanProperty tags: java.util.List[TagRef]
)
@BeanProperty tags: java.util.List[TagRef])

@Service
class SearchResultsService(
Expand All @@ -55,7 +53,7 @@ class SearchResultsService(
def prepare(doc: SearchHit):SearchItem = {
val author = userService.getUserCached(doc.sourceAsMap("author").asInstanceOf[String])

val postdate = isoDateTime.parseDateTime(doc.sourceAsMap("postdate").asInstanceOf[String])
val postdate = Instant.parse(doc.sourceAsMap("postdate").asInstanceOf[String])

val comment = doc.sourceAsMap("is_comment").asInstanceOf[Boolean]

Expand All @@ -72,7 +70,7 @@ class SearchResultsService(

SearchItem(
title = getTitle(doc),
postdate = postdate,
postdate = Date.from(postdate),
user = author,
url = getUrl(doc),
score = doc.score,
Expand Down Expand Up @@ -120,7 +118,7 @@ class SearchResultsService(
FacetItem(urlName, s"$name ($count)")
}

val agg = sectionFacet.terms("sections")
val agg = sectionFacet.result[Terms]("sections")

val items = for (entry <- agg.buckets) yield {
mkItem(entry.key, entry.docCount)
Expand All @@ -142,7 +140,7 @@ class SearchResultsService(

val facetItems = for {
selectedSection <- maybeSection.toSeq
groups = selectedSection.terms("groups")
groups = selectedSection.result[Terms]("groups")
section = sectionService.getSectionByName(selectedSection.key)
entry <- groups.buckets
} yield {
Expand Down Expand Up @@ -172,8 +170,6 @@ class SearchResultsService(
}

object SearchResultsService {
private val isoDateTime = ISODateTimeFormat.dateTime

def postdate(doc: SearchHit) = Instant.parse(doc.sourceAsMap("postdate").asInstanceOf[String])
def section(doc: SearchHit) = doc.sourceAsMap("section").asInstanceOf[String]
def group(doc: SearchHit) = doc.sourceAsMap("group").asInstanceOf[String]
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/jsp/search.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%@ taglib prefix="l" uri="http://www.linux.org.ru" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
~ Copyright 1998-2021 Linux.org.ru
~ Copyright 1998-2024 Linux.org.ru
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
Expand Down Expand Up @@ -136,7 +136,7 @@
</c:if>

<div class=sign>
<lor:sign postdate="${item.postdate.toDate()}" shortMode="false" user="${item.user}"/>
<lor:sign postdate="${item.postdate}" shortMode="false" user="${item.user}"/>
</div>

<c:if test="${param.debug}"><div>Rank: ${item.score}</div></c:if>
Expand Down

0 comments on commit 7fe814e

Please sign in to comment.