|
@@ -23,7 +23,6 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|
|
var searchResultCounts = 0
|
|
var searchResultCounts = 0
|
|
|
val cacheChapterNames = hashSetOf<String>()
|
|
val cacheChapterNames = hashSetOf<String>()
|
|
|
val searchResultList: MutableList<SearchResult> = mutableListOf()
|
|
val searchResultList: MutableList<SearchResult> = mutableListOf()
|
|
|
- var mContent: String = ""
|
|
|
|
|
|
|
|
|
|
fun initBook(bookUrl: String, success: () -> Unit) {
|
|
fun initBook(bookUrl: String, success: () -> Unit) {
|
|
|
this.bookUrl = bookUrl
|
|
this.bookUrl = bookUrl
|
|
@@ -45,9 +44,9 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|
|
if (chapter != null) {
|
|
if (chapter != null) {
|
|
|
book?.let { book ->
|
|
book?.let { book ->
|
|
|
val chapterContent = BookHelp.getContent(book, chapter)
|
|
val chapterContent = BookHelp.getContent(book, chapter)
|
|
|
|
|
+ val mContent: String
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
if (chapterContent != null) {
|
|
if (chapterContent != null) {
|
|
|
- //先搜索没有启用净化的正文
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
withContext(Dispatchers.IO) {
|
|
|
chapter.title = when (AppConfig.chineseConverterType) {
|
|
chapter.title = when (AppConfig.chineseConverterType) {
|
|
|
1 -> ChineseUtils.t2s(chapter.title)
|
|
1 -> ChineseUtils.t2s(chapter.title)
|
|
@@ -56,13 +55,10 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|
|
}
|
|
}
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
mContent = contentProcessor!!.getContent(
|
|
mContent = contentProcessor!!.getContent(
|
|
|
- book, chapter, chapterContent,
|
|
|
|
|
- chineseConvert = true,
|
|
|
|
|
- reSegment = false,
|
|
|
|
|
- useReplace = false
|
|
|
|
|
|
|
+ book, chapter, chapterContent
|
|
|
).joinToString("")
|
|
).joinToString("")
|
|
|
}
|
|
}
|
|
|
- val positions = searchPosition(query)
|
|
|
|
|
|
|
+ val positions = searchPosition(mContent, query)
|
|
|
positions.forEachIndexed { index, position ->
|
|
positions.forEachIndexed { index, position ->
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
val construct = getResultAndQueryIndex(mContent, position, query)
|
|
val construct = getResultAndQueryIndex(mContent, position, query)
|
|
@@ -84,20 +80,13 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
|
|
return searchResultsWithinChapter
|
|
return searchResultsWithinChapter
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private suspend fun searchPosition(pattern: String): List<Int> {
|
|
|
|
|
|
|
+ private suspend fun searchPosition(content: String, pattern: String): List<Int> {
|
|
|
val position: MutableList<Int> = mutableListOf()
|
|
val position: MutableList<Int> = mutableListOf()
|
|
|
- var index = mContent.indexOf(pattern)
|
|
|
|
|
- if (index >= 0) {
|
|
|
|
|
- //搜索到内容允许净化
|
|
|
|
|
- if (book!!.getUseReplaceRule()) {
|
|
|
|
|
- mContent = contentProcessor!!.replaceContent(mContent)
|
|
|
|
|
- index = mContent.indexOf(pattern)
|
|
|
|
|
- }
|
|
|
|
|
- while (index >= 0) {
|
|
|
|
|
- coroutineContext.ensureActive()
|
|
|
|
|
- position.add(index)
|
|
|
|
|
- index = mContent.indexOf(pattern, index + pattern.length)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var index = content.indexOf(pattern)
|
|
|
|
|
+ while (index >= 0) {
|
|
|
|
|
+ coroutineContext.ensureActive()
|
|
|
|
|
+ position.add(index)
|
|
|
|
|
+ index = content.indexOf(pattern, index + pattern.length)
|
|
|
}
|
|
}
|
|
|
return position
|
|
return position
|
|
|
}
|
|
}
|