Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ Pods/
*.gpg
*yarn.lock
.claude/

# Kotlin SwiftPM import (Sentry Cocoa for the iOS binaries)
.swiftpm-locks/
21 changes: 17 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ through `SiddurFeature`/`installedSiddur`, never by importing `addons/siddur` co
The semantic search (own embedding model, dense KNN fused with lexical search by RRF) follows the same pattern: the
private `io.github.kdroidfilter:seforim-semantic` package (module `semantic/` of the private `SeforimEmbedding` repo,
read with the siddur's token by default, or `semantic.token`/`SEFORIM_SEMANTIC_TOKEN`/`gh`, or `-Psemantic.local=true`),
whose jar carries the int8 model as a resource (never in the DB bundle). `addons/semantic/enabled` holds the
`HybridSearchEngine`; `disabled` makes `installedSemanticSearch` null and the app uses `LuceneSearchEngine` alone. Core
code reaches it only through `SemanticSearchFeature`/`installedSemanticSearch`. With the same token, SeforimLibrary's
generator embeds the corpus into the index's vectors (`:searchindex:embedCorpus`, GPU via CUDA, no Python).
Kotlin Multiplatform since 0.6.0, whose JVM jar carries the int8 model as a resource (never in the DB bundle; mobile
apps download it). `searchkit/addons/semantic/enabled` holds the `HybridSearchEngine`; `disabled` makes
`installedSemanticSearch` null and the app searches lexically alone. Core code reaches it only through
`SemanticSearchFeature`/`installedSemanticSearch`. With the same token, SeforimLibrary's generator embeds the corpus
into the index's vectors (`:searchindex:embedCorpus`, GPU via CUDA, no Python).

### Search on mobile: `searchkit`
The search without its UI (engines, lookup, use cases, `SearchResultViewModel`/`SearchHomeViewModel`) is the KMP module
`searchkit` (JVM, Android 10+, iOS), shared by the desktop and the mobile apps; see `searchkit/README.md`. Lucene runs
on a real JVM only (ART can't keep up with Lucene's Java versions), through Nucleus JVM Access: SeforimLibrary's
`search-facade` (Kotlin/JVM) is the façade, its common code uses the `LuceneIndex`/`IndexQuery`... NJA generates; the
desktop's own JVM, HotSpot in the app's process on Android (jdk-mobile's OpenJDK 27), a GraalVM native image linked
into the app on iOS (graalvm-mobile);
see `SeforimLibrary/JVM_RUNTIME.md`. The view models reach the
desktop shell only through the ports of `SearchHost.kt` (`SearchTabs`, `SearchSessionStore`, `SearchSettings`,
`SearchHistory`); keep `java.*`, AWT and desktop types out of `searchkit/src/commonMain`.

The verse quote links of the Talmud (temporary, until the DB carries them) follow the same pattern: the private
`io.github.kdroidfilter:seforim-quotelinks` package (repo `SeforimQuoteLinks`, read with the siddur's token by default,
Expand Down Expand Up @@ -157,6 +169,7 @@ See `TAB_SYSTEM_README.md` for complete details. Key points:
- `pagination`: Pagination support for large datasets
- `texteffects`: Text rendering effects and styling
- `network`: Network utilities and Ktor client setup
- `searchkit`: the search without its UI, multiplatform (see "Search on mobile")
- `backup`: Backup core, Android-BackupAgent/Transport style: `BackupSource` (what: the app's `UserDataBackup`, user DB + portable prefs), `BackupDestination` (where: `LocalFileDestination`, …), `BackupManager` (the only code linking both)
- `backup-drive`: Google Drive `BackupDestination` + `GoogleDriveSync` (OAuth PKCE loopback, hidden `appDataFolder`, append-only with the 10 latest kept as IntelliJ settings sync, never restores without asking, on-quit + daily auto backup paused while a restore is pending)

Expand Down

This file was deleted.

13 changes: 4 additions & 9 deletions SeforimApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ sentry {
// (settings.gradle.kts); a community build has none and addons/siddur/disabled says so
val withSiddur = gradle.extensions.extraProperties["siddurEnabled"] == true

// The semantic search too (open core): its package (code + model) with its token or its sources beside; without
// them, addons/semantic/disabled leaves the search lexical only
val withSemantic = gradle.extensions.extraProperties["semanticEnabled"] == true

// The verse quote links of the Talmud (open core, temporary until the DB carries them): its package, or
// addons/quotelinks/disabled and the reader shows the lines as they are
val withQuoteLinks = gradle.extensions.extraProperties["quoteLinksEnabled"] == true
Expand Down Expand Up @@ -145,11 +141,6 @@ kotlin {
}
if (withSiddur) jvmTest { kotlin.srcDir("addons/siddur/test/kotlin") }

jvmMain {
kotlin.srcDir(if (withSemantic) "addons/semantic/enabled/kotlin" else "addons/semantic/disabled/kotlin")
if (withSemantic) dependencies { implementation(libs.seforim.semantic) }
}

jvmMain {
kotlin.srcDir(if (withQuoteLinks) "addons/quotelinks/enabled/kotlin" else "addons/quotelinks/disabled/kotlin")
if (withQuoteLinks) dependencies { implementation(libs.seforim.quotelinks) }
Expand Down Expand Up @@ -199,6 +190,10 @@ kotlin {
// SeforimLibrary search module
implementation(libs.seforimlibrary.search)

// The search without its UI (engines, lookup, use cases, view models), shared with the mobile apps; the
// semantic search (open core) comes with it in the official builds
implementation(project(":searchkit"))

// SeforimLibrary CLI: lets the desktop binary run headless search commands
// (`zayit cli search ...`) by delegating to its runCli() entry point.
implementation(libs.seforimlibrary.cli)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Stable
import io.github.kdroidfilter.seforim.tabs.SearchScope
import io.github.kdroidfilter.seforimapp.db.UserSettingsDb
import io.github.kdroidfilter.seforimapp.db.Visit_history
import io.github.kdroidfilter.seforimapp.features.search.SearchHistory
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -39,7 +40,7 @@ enum class VisitKind { BOOK, SEARCH }
*/
class HistoryStore(
database: UserSettingsDb,
) {
) : SearchHistory {
private val queries = database.visitHistoryQueries

private val _revision = MutableStateFlow(0L)
Expand Down Expand Up @@ -79,7 +80,7 @@ class HistoryStore(
* Records an executed search with the [scope] it ran in: one history row per (query, scope, extended), titled
* with [scopeLabel] (the scope's name) so a scoped search reads apart from the same query elsewhere.
*/
suspend fun recordSearchVisit(
override suspend fun recordSearchVisit(
query: String,
scope: SearchScope,
globalExtended: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.zacsweers.metro.SingleIn
import io.github.kdroidfilter.seforimapp.core.presentation.theme.AccentColor
import io.github.kdroidfilter.seforimapp.core.presentation.theme.IntUiThemes
import io.github.kdroidfilter.seforimapp.earthwidget.WidgetAntiAliasing
import io.github.kdroidfilter.seforimapp.features.search.SearchSettings
import io.github.kdroidfilter.seforimapp.framework.di.AppScope
import io.github.kdroidfilter.seforimapp.framework.platform.PlatformInfo
import kotlinx.coroutines.channels.BufferOverflow
Expand All @@ -28,10 +29,10 @@ import java.util.concurrent.ConcurrentHashMap
@SingleIn(AppScope::class)
class AppSettings(
private val settings: Settings,
) {
) : SearchSettings {
// StateFlow to observe text size changes
private val _textSizeFlow = MutableStateFlow(getTextSize())
val textSizeFlow: StateFlow<Float> = _textSizeFlow.asStateFlow()
override val textSizeFlow: StateFlow<Float> = _textSizeFlow.asStateFlow()

// StateFlow to observe line height changes
private val _lineHeightFlow = MutableStateFlow(getLineHeight())
Expand Down Expand Up @@ -119,7 +120,7 @@ class AppSettings(

fun findQueryFlow(tabId: String): StateFlow<String> = queryFlowFor(tabId).asStateFlow()

fun setFindQuery(
override fun setFindQuery(
tabId: String,
q: String,
) {
Expand All @@ -128,7 +129,7 @@ class AppSettings(

fun findBarOpenFlow(tabId: String): StateFlow<Boolean> = findOpenFlowFor(tabId).asStateFlow()

fun openFindBar(tabId: String) {
override fun openFindBar(tabId: String) {
findOpenFlowFor(tabId).value = true
}

Expand Down Expand Up @@ -169,7 +170,7 @@ class AppSettings(

fun findSmartModeFlow(tabId: String): StateFlow<Boolean> = smartModeFlowFor(tabId).asStateFlow()

fun setFindSmartMode(
override fun setFindSmartMode(
tabId: String,
enabled: Boolean,
) {
Expand All @@ -181,7 +182,7 @@ class AppSettings(
flow.value = !flow.value
}

fun getTextSize(): Float = settings[KEY_TEXT_SIZE, DEFAULT_TEXT_SIZE]
override fun getTextSize(): Float = settings[KEY_TEXT_SIZE, DEFAULT_TEXT_SIZE]

fun setTextSize(size: Float) {
settings[KEY_TEXT_SIZE] = size
Expand Down Expand Up @@ -425,13 +426,13 @@ class AppSettings(
// User profile accessors
// Reactive flows to observe user identity changes across the app
private val _userFirstNameFlow = MutableStateFlow(getUserFirstName() ?: "")
val userFirstNameFlow: StateFlow<String> = _userFirstNameFlow.asStateFlow()
override val userFirstNameFlow: StateFlow<String> = _userFirstNameFlow.asStateFlow()

private val _userLastNameFlow = MutableStateFlow(getUserLastName() ?: "")
val userLastNameFlow: StateFlow<String> = _userLastNameFlow.asStateFlow()
override val userLastNameFlow: StateFlow<String> = _userLastNameFlow.asStateFlow()

private val _userCommunityCodeFlow = MutableStateFlow(getUserCommunityCode())
val userCommunityCodeFlow: StateFlow<String?> = _userCommunityCodeFlow.asStateFlow()
override val userCommunityCodeFlow: StateFlow<String?> = _userCommunityCodeFlow.asStateFlow()

fun getUserFirstName(): String? {
val value: String = settings[KEY_USER_FIRST_NAME, ""]
Expand Down Expand Up @@ -631,7 +632,7 @@ class AppSettings(
}

// Text size constants
const val DEFAULT_TEXT_SIZE = 16f
const val DEFAULT_TEXT_SIZE = SearchSettings.DEFAULT_TEXT_SIZE
const val MIN_TEXT_SIZE = 14f
const val MAX_TEXT_SIZE = 50f
const val TEXT_SIZE_INCREMENT = 2f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ fun SearchBookTocPanel(
onHide = { onEvent(BookContentEvent.ToggleToc) },
)
Column(modifier = Modifier.padding(horizontal = 8.dp)) {
if (searchUi.scopeBook != null) {
val scopeBook = searchUi.scopeBook
if (scopeBook != null) {
Box(modifier = Modifier.fillMaxHeight()) {
val expanded: Set<Long> = uiState.toc.expandedEntries
var autoExpanded by remember(searchUi.scopeBook.id, tocCounts, tocTree) { mutableStateOf(false) }
LaunchedEffect(searchUi.scopeBook.id, tocCounts, tocTree) {
var autoExpanded by remember(scopeBook.id, tocCounts, tocTree) { mutableStateOf(false) }
LaunchedEffect(scopeBook.id, tocCounts, tocTree) {
if (!autoExpanded) {
val idsWithChildren = tocTree?.children?.keys ?: emptySet()
val withResults = tocCounts.keys
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import io.github.kdroidfilter.seforimapp.core.settings.AppSettings
import io.github.kdroidfilter.seforimapp.core.settings.CategoryDisplaySettingsStore
import io.github.kdroidfilter.seforimapp.core.shnayimmikra.ShnayimMikraStore
import io.github.kdroidfilter.seforimapp.db.UserSettingsDb
import io.github.kdroidfilter.seforimapp.features.search.SearchHistory
import io.github.kdroidfilter.seforimapp.features.search.SearchHomeViewModel
import io.github.kdroidfilter.seforimapp.features.search.SearchSessionStore
import io.github.kdroidfilter.seforimapp.features.search.SearchSettings
import io.github.kdroidfilter.seforimapp.features.search.SearchTabs
import io.github.kdroidfilter.seforimapp.framework.backup.UserDataBackup
import io.github.kdroidfilter.seforimapp.framework.database.CatalogCache
import io.github.kdroidfilter.seforimapp.framework.database.DatabasePathProvider
Expand All @@ -38,8 +42,11 @@ import io.github.kdroidfilter.seforimapp.framework.database.getUserSettingsDatab
import io.github.kdroidfilter.seforimapp.framework.desktop.DesktopManager
import io.github.kdroidfilter.seforimapp.framework.di.AppScope
import io.github.kdroidfilter.seforimapp.framework.search.AcronymFrequencyCache
import io.github.kdroidfilter.seforimapp.framework.search.DesktopSearchSessionStore
import io.github.kdroidfilter.seforimapp.framework.search.DesktopSearchTabs
import io.github.kdroidfilter.seforimapp.framework.search.LuceneLookupSearchService
import io.github.kdroidfilter.seforimapp.framework.search.RepositorySnippetSourceProvider
import io.github.kdroidfilter.seforimapp.framework.search.openLuceneIndex
import io.github.kdroidfilter.seforimapp.framework.search.withSemanticSearch
import io.github.kdroidfilter.seforimapp.framework.session.SessionManager
import io.github.kdroidfilter.seforimapp.framework.session.TabPersistedStateStore
Expand Down Expand Up @@ -190,13 +197,28 @@ object AppCoreBindings {
val dictionaryPath = indexPath.resolveSibling("lexical.db")
val snippetProvider = RepositorySnippetSourceProvider(repository)
val lexical = LuceneSearchEngine(indexPath, snippetProvider, dictionaryPath = dictionaryPath)
return withSemanticSearch(lexical, indexPath, repository)
return withSemanticSearch(lexical, lexical.index, repository)
}

// What the search screens (searchkit) ask of the desktop around them
@Provides
@SingleIn(AppScope::class)
fun provideSearchTabs(desktopManager: DesktopManager): SearchTabs = DesktopSearchTabs(desktopManager)

@Provides
@SingleIn(AppScope::class)
fun provideSearchSessionStore(store: TabPersistedStateStore): SearchSessionStore = DesktopSearchSessionStore(store)

@Provides
fun provideSearchSettings(appSettings: AppSettings): SearchSettings = appSettings

@Provides
fun provideSearchHistory(historyStore: HistoryStore): SearchHistory = historyStore

@Provides
@SingleIn(AppScope::class)
fun provideAcronymFrequencyCache(databasePathProvider: DatabasePathProvider): AcronymFrequencyCache =
AcronymFrequencyCache(databasePathProvider)
AcronymFrequencyCache(databasePathProvider::get)

@Provides
@SingleIn(AppScope::class)
Expand All @@ -206,7 +228,7 @@ object AppCoreBindings {
): LuceneLookupSearchService {
val dbPath = databasePathProvider.get()
val indexPath = if (dbPath.endsWith(".db")) "$dbPath.lookup.lucene" else "$dbPath.lookupindex"
return LuceneLookupSearchService(Paths.get(indexPath), acronymCache = acronymCache)
return LuceneLookupSearchService(openLuceneIndex(indexPath, cacheQueries = true), acronymCache = acronymCache)
}

@Provides
Expand Down Expand Up @@ -269,7 +291,7 @@ object AppCoreBindings {
// created and disposed by DesktopManager.
searchHomeViewModelFactory = { observeProfile ->
SearchHomeViewModel(
persistedStore = tabPersistedStateStore,
sessionStore = DesktopSearchSessionStore(tabPersistedStateStore),
repository = repository,
lookup = lookup,
appSettings = appSettings,
Expand Down
Loading
Loading