Skip to content

Commit 5a4d6cc

Browse files
committed
Semantic search: update API, and enable for FR.
1 parent 26e53d7 commit 5a4d6cc

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

app/src/main/java/org/wikipedia/dataclient/Service.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ interface Service {
5555
"&prop=description|pageimages|pageprops|coordinates|info&ppprop=mainpage|disambiguation" +
5656
"&generator=search&gsrnamespace=0&gsrwhat=text" +
5757
"&inprop=varianttitles|displaytitle" +
58-
"&gsrinfo=&gsrprop=redirecttitle&piprop=thumbnail&pilicense=any&pithumbsize=" +
58+
"&gsrinfo=&gsrprop=redirecttitle|snippet|sectiontitle&piprop=thumbnail&pilicense=any&pithumbsize=" +
5959
PREFERRED_THUMB_SIZE
6060
)
6161
suspend fun fullTextSearch(
6262
@Query("gsrsearch") searchTerm: String?,
6363
@Query("gsrlimit") gsrLimit: Int,
64-
@Query("gsroffset") gsrOffset: Int?
64+
@Query("gsroffset") gsrOffset: Int?,
65+
@Query("cirrusSemanticSearch") isSemantic: Boolean? = null
6566
): MwQueryResponse
6667

6768
@GET(MW_API_PREFIX + "action=query&list=allusers&auwitheditsonly=1")

app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryPage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class MwQueryPage {
4040
val protection: List<Protection> = emptyList()
4141
val extract: String? = null
4242
val snippet: String? = null
43+
@SerialName("sectiontitle") val sectionTitle: String? = null
4344
val description: String? = null
4445
private val imagerepository: String? = null
4546
var redirectFrom: String? = null

app/src/main/java/org/wikipedia/search/HybridSearchAbCTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.wikipedia.WikipediaApp
44
import org.wikipedia.analytics.ABTest
55
import org.wikipedia.settings.Prefs
66
import org.wikipedia.settings.RemoteConfig
7+
import org.wikipedia.util.ReleaseUtil
78

89
class HybridSearchAbCTest : ABTest("apps_hybridsearch", GROUP_SIZE_3) {
910

@@ -28,15 +29,15 @@ class HybridSearchAbCTest : ABTest("apps_hybridsearch", GROUP_SIZE_3) {
2829
}
2930

3031
private fun isLanguageSupported(languageCode: String?): Boolean {
31-
return (RemoteConfig.config.androidv1?.hybridSearchLanguages ?: supportedLanguages).any { it.equals(languageCode, true) }
32+
return ((if (ReleaseUtil.isPreBetaRelease) null else RemoteConfig.config.androidv1?.hybridSearchLanguages) ?: supportedLanguages).any { it.equals(languageCode, true) }
3233
}
3334

3435
fun shouldShowOnboarding(languageCode: String?): Boolean {
3536
return isTestActive() && isTestGroupUser() && isLanguageSupported(languageCode) && !Prefs.isHybridSearchOnboardingShown
3637
}
3738

3839
private val supportedLanguages = listOf(
39-
"el"
40+
"el", "fr"
4041
)
4142

4243
fun isHybridSearchEnabled(languageCode: String?): Boolean {

app/src/main/java/org/wikipedia/search/SearchResult.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
55
import org.wikipedia.dataclient.WikiSite
66
import org.wikipedia.dataclient.mwapi.MwQueryPage
77
import org.wikipedia.page.PageTitle
8+
import org.wikipedia.util.StringUtil
89

910
@Serializable
1011
data class SearchResult(val pageTitle: PageTitle,
@@ -30,7 +31,7 @@ data class SearchResult(val pageTitle: PageTitle,
3031
thumbUrl = page.thumbUrl(),
3132
description = page.description,
3233
displayText = page.displayTitle(wiki.languageCode),
33-
),
34+
).also { if (!page.sectionTitle.isNullOrEmpty()) it.fragment = StringUtil.addUnderscores(page.sectionTitle) },
3435
redirectFrom = page.redirectFrom,
3536
type = type,
3637
coordinates = coordinates,

app/src/main/java/org/wikipedia/search/SearchResultsViewModel.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ class SearchResultsViewModel : ViewModel() {
119119

120120
val semanticDeferred = async {
121121
runCatching {
122-
val tableName = when (lang) {
123-
"el" -> "elwiki_sections"
124-
else -> ""
125-
}
126-
val response = semanticSearchService.search(query = term, count = semanticBatchSize, table = tableName, includeText = true)
127-
val infoResponse = ServiceFactory.get(wikiSite).getInfoByPageIdsOrTitles(titles = response.results.joinToString("|") { it.title })
128-
buildList(response, wikiSite, SearchResult.SearchResultType.SEMANTIC).also { list ->
129-
for (result in list) {
130-
val page = infoResponse.query?.pages?.find { StringUtil.addUnderscores(it.title) == result.pageTitle.prefixedText }
131-
result.pageTitle.thumbUrl = page?.thumbUrl()
132-
result.pageTitle.description = page?.description
122+
if (lang == "el") {
123+
val response = semanticSearchService.search(query = term, count = semanticBatchSize, table = "elwiki_sections", includeText = true)
124+
val infoResponse = ServiceFactory.get(wikiSite).getInfoByPageIdsOrTitles(titles = response.results.joinToString("|") { it.title })
125+
buildList(response, wikiSite, SearchResult.SearchResultType.SEMANTIC).also { list ->
126+
for (result in list) {
127+
val page = infoResponse.query?.pages?.find { StringUtil.addUnderscores(it.title) == result.pageTitle.prefixedText }
128+
result.pageTitle.thumbUrl = page?.thumbUrl()
129+
result.pageTitle.description = page?.description
130+
}
133131
}
132+
} else {
133+
val response = ServiceFactory.get(wikiSite).fullTextSearch(term, lexicalBatchSize, 0, isSemantic = true)
134+
buildList(response, invokeSource, wikiSite, type = SearchResult.SearchResultType.SEMANTIC)
134135
}
135136
}
136137
}

0 commit comments

Comments
 (0)