Skip to content

Commit

Permalink
fix them
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Dec 5, 2024
1 parent b84007b commit 767a9f2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 76 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SearchApiProperties extends BaseProps with StrictLogging {
case `draftIndexName` => Success(SearchType.Drafts)
case `learningpathIndexName` => Success(SearchType.LearningPaths)
case `conceptIndexName` => Success(SearchType.Concepts)
case `grepIndexName` => Success(SearchType.Grep)
case _ => Failure(new IllegalArgumentException(s"Unknown index name: $indexName"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,14 @@ trait InternController {
draftIndexService.cleanupIndexes(): Unit
learningPathIndexService.cleanupIndexes(): Unit
draftConceptIndexService.cleanupIndexes(): Unit
grepIndexService.cleanupIndexes(): Unit

val articles = articleIndexService.reindexWithShards(numShards)
val drafts = draftIndexService.reindexWithShards(numShards)
val learningpaths = learningPathIndexService.reindexWithShards(numShards)
val concept = draftConceptIndexService.reindexWithShards(numShards)
List(articles, drafts, learningpaths, concept).sequence match {
val greps = grepIndexService.reindexWithShards(numShards)
List(articles, drafts, learningpaths, concept, greps).sequence match {
case Success(_) =>
s"Reindexing with $numShards shards completed in ${System.currentTimeMillis() - startTime}ms".asRight
case Failure(ex) =>
Expand All @@ -298,12 +300,14 @@ trait InternController {
draftIndexService.cleanupIndexes(): Unit
learningPathIndexService.cleanupIndexes(): Unit
draftConceptIndexService.cleanupIndexes(): Unit
grepIndexService.cleanupIndexes(): Unit

val articles = articleIndexService.updateReplicaNumber(numReplicas)
val drafts = draftIndexService.updateReplicaNumber(numReplicas)
val learningpaths = learningPathIndexService.updateReplicaNumber(numReplicas)
val concepts = draftConceptIndexService.updateReplicaNumber(numReplicas)
List(articles, drafts, learningpaths, concepts).sequence match {
val greps = grepIndexService.updateReplicaNumber(numReplicas)
List(articles, drafts, learningpaths, concepts, greps).sequence match {
case Success(_) =>
s"Updated replication setting for indexes to $numReplicas replicas. Populating may take some time.".asRight
case Failure(ex) =>
Expand Down Expand Up @@ -344,6 +348,7 @@ trait InternController {
articleIndexService.cleanupIndexes(): Unit
draftIndexService.cleanupIndexes(): Unit
draftConceptIndexService.cleanupIndexes(): Unit
grepIndexService.cleanupIndexes(): Unit

val publishedIndexingBundle = IndexingBundle(
grepBundle = Some(grepBundle),
Expand Down Expand Up @@ -374,6 +379,10 @@ trait InternController {
Future {
requestInfo.setThreadContextRequestInfo()
("concepts", draftConceptIndexService.indexDocuments(numShards, draftIndexingBundle))
},
Future {
requestInfo.setThreadContextRequestInfo()
("greps", grepIndexService.indexDocuments(numShards, Some(grepBundle)))
}
)
if (runInBackground) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object SearchType extends Enum[SearchType] with CirceEnumWithErrors[SearchType]
case object Drafts extends SearchType("draft")
case object LearningPaths extends SearchType("learningpath")
case object Concepts extends SearchType("concept")
case object Grep extends SearchType("grep") // TODO: Er dette dumt?
case object Grep extends SearchType("grep")

def all: List[String] = SearchType.values.map(_.toString).toList
override def values: IndexedSeq[SearchType] = findValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait GrepIndexService {

override def getMapping: MappingDefinition = {
val fields = List(keywordField("code"))
val dynamics = generateLanguageSupportedDynamicTemplates("title", disableSubfields = true)
val dynamics = generateLanguageSupportedDynamicTemplates("title", keepRaw = true)

properties(fields).dynamicTemplates(dynamics)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ trait GrepSearchService {
boost,
searchLanguage,
fallback = true,
searchDecompounded = false // TODO: Vil vi ha denne?
searchDecompounded = true
)
boolQuery()
.should(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ trait IndexService {
*/
protected def generateLanguageSupportedDynamicTemplates(
fieldName: String,
keepRaw: Boolean = false,
disableSubfields: Boolean = false
keepRaw: Boolean = false
): Seq[DynamicTemplateRequest] = {
val dynamicFunc = (name: String, analyzer: String, subFields: List[ElasticField]) => {
val field = textField(name).analyzer(analyzer)
val withSubfields = if (disableSubfields) field else field.fields(subFields)
val field = textField(name).analyzer(analyzer).fields(subFields)
DynamicTemplateRequest(
name = name,
mapping = withSubfields,
mapping = field,
matchMappingType = Some("string"),
pathMatch = Some(name)
)
Expand All @@ -76,6 +74,36 @@ trait IndexService {
val catchAllSubTemplate = dynamicFunc(s"*.$fieldName.*", "standard", subFields)
languageTemplates ++ languageSubTemplates ++ Seq(catchAllTemplate, catchAllSubTemplate)
}

private val hyphDecompounderTokenFilter: CompoundWordTokenFilter = CompoundWordTokenFilter(
name = "hyphenation_decompounder",
`type` = HyphenationDecompounder,
wordListPath = Some("compound-words-norwegian-wordlist.txt"),
hyphenationPatternsPath = Some("hyph/no.xml"),
minSubwordSize = Some(4),
onlyLongestMatch = Some(false)
)

private val customCompoundAnalyzer =
CustomAnalyzer(
"compound_analyzer",
"whitespace",
tokenFilters = List(hyphDecompounderTokenFilter.name)
)

private val customExactAnalyzer = CustomAnalyzer("exact", "whitespace")

val shingle: ShingleTokenFilter =
ShingleTokenFilter(name = "shingle", minShingleSize = Some(2), maxShingleSize = Some(3))

val trigram: CustomAnalyzer =
CustomAnalyzer(name = "trigram", tokenizer = "standard", tokenFilters = List("lowercase", "shingle"))

override val analysis: Analysis =
Analysis(
analyzers = List(trigram, customExactAnalyzer, customCompoundAnalyzer, NynorskLanguageAnalyzer),
tokenFilters = List(hyphDecompounderTokenFilter) ++ SearchLanguage.NynorskTokenFilters
)
}

trait IndexService[D <: Content] extends BulkIndexingService with StrictLogging {
Expand Down Expand Up @@ -228,36 +256,6 @@ trait IndexService {
}
}

private val hyphDecompounderTokenFilter: CompoundWordTokenFilter = CompoundWordTokenFilter(
name = "hyphenation_decompounder",
`type` = HyphenationDecompounder,
wordListPath = Some("compound-words-norwegian-wordlist.txt"),
hyphenationPatternsPath = Some("hyph/no.xml"),
minSubwordSize = Some(4),
onlyLongestMatch = Some(false)
)

private val customCompoundAnalyzer =
CustomAnalyzer(
"compound_analyzer",
"whitespace",
tokenFilters = List(hyphDecompounderTokenFilter.name)
)

private val customExactAnalyzer = CustomAnalyzer("exact", "whitespace")

val shingle: ShingleTokenFilter =
ShingleTokenFilter(name = "shingle", minShingleSize = Some(2), maxShingleSize = Some(3))

val trigram: CustomAnalyzer =
CustomAnalyzer(name = "trigram", tokenizer = "standard", tokenFilters = List("lowercase", "shingle"))

override val analysis: Analysis =
Analysis(
analyzers = List(trigram, customExactAnalyzer, customCompoundAnalyzer, NynorskLanguageAnalyzer),
tokenFilters = List(hyphDecompounderTokenFilter) ++ SearchLanguage.NynorskTokenFilters
)

/** Returns Sequence of FieldDefinitions for a given field.
*
* @param fieldName
Expand Down
5 changes: 2 additions & 3 deletions search/src/main/scala/no/ndla/search/BaseIndexService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ trait BaseIndexService {
if (indexWithNameExists(indexName).getOrElse(false)) {
Success(indexName)
} else {
val response = e4sClient.execute {
buildCreateIndexRequest(indexName, numShards)
}
val request = buildCreateIndexRequest(indexName, numShards)
val response = e4sClient.execute(request)

response match {
case Success(_) => Success(indexName)
Expand Down

0 comments on commit 767a9f2

Please sign in to comment.