Skip to content
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

Add indexing and searching for contextids #566

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ case class SearchableArticle(
defaultTitle: Option[String],
supportedLanguages: List[String],
contexts: List[SearchableTaxonomyContext],
contextids: List[String],
grepContexts: List[SearchableGrepContext],
traits: List[String],
embedAttributes: SearchableLanguageList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ case class SearchableDraft(
supportedLanguages: List[String],
notes: List[String],
contexts: List[SearchableTaxonomyContext],
contextids: List[String],
draftStatus: SearchableStatus,
users: List[String],
previousVersionsNotes: List[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ case class SearchableLearningPath(
supportedLanguages: List[String],
authors: List[String],
contexts: List[SearchableTaxonomyContext],
contextids: List[String],
favorited: Long,
learningResourceType: LearningResourceType
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ case class Node(
name: String,
contentUri: Option[String],
path: Option[String],
url: Option[String],
metadata: Option[Metadata],
translations: List[TaxonomyTranslation],
nodeType: NodeType,
contextids: List[String],
var contexts: List[TaxonomyContext]
)

Expand All @@ -43,11 +45,13 @@ object Node {
name <- c.downField("name").as[Option[String]].map(_.getOrElse(""))
contentUri <- c.downField("contentUri").as[Option[String]]
path <- c.downField("path").as[Option[String]]
url <- c.downField("url").as[Option[String]]
metadata <- c.downField("metadata").as[Option[Metadata]]
translations <- c.downField("translations").as[List[TaxonomyTranslation]]
nodeType <- c.downField("nodeType").as[NodeType]
contextids <- c.downField("contextids").as[List[String]]
contexts <- c.downField("contexts").as[List[TaxonomyContext]]
} yield Node(id, name, contentUri, path, metadata, translations, nodeType, contexts)
} yield Node(id, name, contentUri, path, url, metadata, translations, nodeType, contextids, contexts)

})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ trait ArticleIndexService {
keywordField("availability"),
keywordField("learningResourceType"),
getTaxonomyContextMapping,
keywordField("contextids"),
nestedField("embedResourcesAndIds").fields(
keywordField("resource"),
keywordField("id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ trait DraftIndexService {
)
),
getTaxonomyContextMapping,
keywordField("contextids"),
nestedField("embedResourcesAndIds").fields(
keywordField("resource"),
keywordField("id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ trait LearningPathIndexService {
intField("isBasedOn"),
keywordField("supportedLanguages"),
getTaxonomyContextMapping,
keywordField("contextids"),
nestedField("embedResourcesAndIds").fields(
keywordField("resource"),
keywordField("id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ trait MultiDraftSearchService {
simpleStringQuery(queryString.underlying).field("grepContexts.title", 1),
nestedQuery("contexts", boolQuery().should(termQuery("contexts.contextId", queryString.underlying)))
.ignoreUnmapped(true),
boolQuery().should(termQuery("contextids", queryString.underlying)),
gunnarvelle marked this conversation as resolved.
Show resolved Hide resolved
idsQuery(queryString.underlying),
nestedQuery("revisionMeta", simpleStringQuery(queryString.underlying).field("revisionMeta.note"))
.ignoreUnmapped(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ trait MultiSearchService {
simpleStringQuery(q.underlying).field("authors", 1),
simpleStringQuery(q.underlying).field("grepContexts.title", 1),
nestedQuery("contexts", boolQuery().should(termQuery("contexts.contextId", q.underlying))),
boolQuery().should(termQuery("contextids", q.underlying)),
gunnarvelle marked this conversation as resolved.
Show resolved Hide resolved
idsQuery(q.underlying)
) ++
buildNestedEmbedField(List(q.underlying), None, settings.language, settings.fallback) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ trait SearchConverterService {
defaultTitle = defaultTitle.map(t => t.title),
supportedLanguages = supportedLanguages,
contexts = asSearchableTaxonomyContexts(taxonomyContexts.getOrElse(List.empty)),
contextids =
indexingBundle.taxonomyBundle.map(getTaxonomyContexids(articleId, "article", _)).getOrElse(List.empty),
grepContexts = getGrepContexts(ai.grepCodes, indexingBundle.grepBundle),
traits = traits.toList.distinct,
embedAttributes = embedAttributes,
Expand Down Expand Up @@ -294,6 +296,8 @@ trait SearchConverterService {
supportedLanguages = supportedLanguages,
authors = lp.copyright.contributors.map(_.name).toList,
contexts = asSearchableTaxonomyContexts(taxonomyContexts.getOrElse(List.empty)),
contextids =
indexingBundle.taxonomyBundle.map(getTaxonomyContexids(lp.id.get, "learningpath", _)).getOrElse(List.empty),
favorited = favorited,
learningResourceType = LearningResourceType.LearningPath
)
Expand Down Expand Up @@ -464,6 +468,8 @@ trait SearchConverterService {
supportedLanguages = supportedLanguages,
notes = notes,
contexts = asSearchableTaxonomyContexts(taxonomyContexts),
contextids =
indexingBundle.taxonomyBundle.map(getTaxonomyContexids(draft.id.get, "article", _)).getOrElse(List.empty),
users = users.distinct,
previousVersionsNotes = draft.previousVersionsNotes.map(_.note).toList,
grepContexts = getGrepContexts(draft.grepCodes, indexingBundle.grepBundle),
Expand Down Expand Up @@ -913,6 +919,22 @@ trait SearchConverterService {
if (filterContexts) visibles.filter(c => c.rootId.contains("subject")) else visibles
}

/** Parses [[TaxonomyBundle]] to get all contextids for a single node.
*
* @param id
* of article/learningpath
* @param taxonomyType
* Type of resource used in contentUri. Example: "learningpath" in "urn:learningpath:123"
* @param bundle
* All taxonomy in an object.
* @return
* List of strings to be indexed.
*/
private def getTaxonomyContexids(id: Long, taxonomyType: String, bundle: TaxonomyBundle) = {
val nodes = bundle.nodeByContentUri.getOrElse(s"urn:$taxonomyType:$id", List.empty)
nodes.flatMap(node => node.contextids)
}

private[service] def getGrepContexts(
grepCodes: Seq[String],
bundle: Option[GrepBundle]
Expand Down
Loading
Loading