-
-
Notifications
You must be signed in to change notification settings - Fork 27
blog search #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
blog search #499
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
13e0819
blog search
schlawg 03c130c
option for results by score
schlawg 025cc34
fix copy paste error caught in review
schlawg 9759fe6
remove comments and redundancies, dont index spam
schlawg afade6b
Update scala3-library to 3.7.1
scala-steward bae3982
Update smithy4s-core, smithy4s-http4s, ... to 0.18.37
scala-steward ee2f4a0
Add -Wall which warns everything
lenguyenthanh 29fb7e7
Fix warnings from Wtostring-interpolated
lenguyenthanh 76251cb
Update log4cats-slf4j to 2.7.1
scala-steward 1a68dac
Update weaver-cats, weaver-scalacheck to 0.9.0
scala-steward 30e01ca
Use named tuple for SourceWithId
lenguyenthanh 051db4a
Remove a superfulous comment
lenguyenthanh b226d82
Fix test compilation and remove nowarns
lenguyenthanh 9954c65
Setting version to 3.1.9
lenguyenthanh 07381f9
Setting version to 3.1.10-SNAPSHOT
lenguyenthanh e3a2b74
improve search quality, add boolean AND
schlawg 4a62dc2
use language string constant
schlawg 8c0e5ff
add sort by likes
schlawg 34dae2f
Merge branch 'master' into ublog-search
schlawg 692deef
scalafix
schlawg 5a7588c
been a long time since jdk 8
schlawg f4aee4e
Merge remote-tracking branch 'upstream/master' into ublog-search
schlawg 01b6e2a
reflect recent enum constant capitalization change in lila
schlawg 7730ca5
fix test
schlawg 355eadb
Merge branch 'master' into ublog-search
ornicar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package lila.search | ||
| package ublog | ||
|
|
||
| import com.sksamuel.elastic4s.ElasticDsl.* | ||
| import com.sksamuel.elastic4s.requests.searches.sort.SortOrder | ||
|
|
||
| import spec.SortBlogsBy | ||
|
|
||
| case class Ublog( | ||
| queryText: String, | ||
| by: SortBlogsBy, | ||
| minQuality: Option[Int], | ||
| language: Option[String] | ||
| ): | ||
|
|
||
| val sanitized = queryText | ||
| .trim() | ||
| .toLowerCase() | ||
| .replaceAll("""([\-=&|><!(){}\[\]^"~*?\\/])""", """\\$1""") | ||
| .replaceAll(" and ", " AND ") | ||
| .replaceAll("\\+", " AND ") | ||
| .split("\\s+") | ||
| .map: | ||
| case s if s.matches("language:[a-z]{2}") || s.matches("quality:[1-3]") => s | ||
| case s => s.replace(":", " ") // devs can use the query string until we get a ui for lang/quality | ||
| .mkString(" ") | ||
|
|
||
| def searchDef(from: From, size: Size) = | ||
| val sortFields = | ||
| (if by == SortBlogsBy.score then Seq(scoreSort().order(SortOrder.DESC)) | ||
| else if by == SortBlogsBy.likes then Seq(fieldSort("likes").order(SortOrder.DESC)) | ||
| else Nil) ++ Seq( | ||
| fieldSort("quality").order(SortOrder.DESC).missing("_last"), | ||
| fieldSort("date") | ||
| .order(if by == SortBlogsBy.oldest then SortOrder.ASC else SortOrder.DESC) | ||
| .missing("_last") | ||
| ) | ||
| search(Ublog.index) | ||
| .query(makeQuery()) | ||
| .fetchSource(false) | ||
| .sortBy(sortFields*) | ||
| .start(from.value) | ||
| .size(size.value) | ||
|
|
||
| def countDef = count(Ublog.index).query(makeQuery()) | ||
|
|
||
| private def makeQuery() = | ||
| boolQuery() | ||
| .must(queryStringQuery(sanitized).defaultField(Fields.text)) | ||
| .filter( | ||
| List( | ||
| minQuality.map(f => rangeQuery(Fields.quality).gte(f)), | ||
| language.map(l => termQuery(Fields.language, l)) | ||
| ).flatten | ||
| ) | ||
|
|
||
| object Ublog: | ||
| val index = "ublog" | ||
|
|
||
| object Fields: | ||
| val text = "text" | ||
| val likes = "likes" | ||
| val quality = "quality" | ||
| val language = "language" | ||
| val date = "date" | ||
|
|
||
| object Mapping: | ||
| import Fields.* | ||
| def fields = | ||
| Seq( | ||
| textField(text), | ||
| shortField(quality).copy(docValues = Some(true)), | ||
| keywordField(language).copy(docValues = Some(false)), | ||
| shortField(likes).copy(docValues = Some(true)), | ||
| dateField(date).copy(docValues = Some(true)) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a curious question, why does some fields keep values, some don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that disabling docValues on fields you don’t sort/aggregate keeps segment size smaller. language would only ever be filtered or searched. it wouldn't be sorted.