-
Notifications
You must be signed in to change notification settings - Fork 199
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
Search results with statistics #2061
base: develop
Are you sure you want to change the base?
Changes from all commits
5a0d132
8376a93
1b1195f
8f12d36
856333a
15f6d79
c799b52
2fd5daf
1813f7b
429825f
42fa539
07e674c
210ca69
2966e8b
1764f3b
3f1a7c6
68bd008
fd39490
d899246
92c32dd
faea5de
7217619
61333bb
2bc8c70
1401604
5b0b478
f10c554
7995ad1
e3b2f61
267621e
4c49984
46c8592
97aaa48
4ee12de
b3751c8
d0bdd5a
8be3724
478e418
b530111
7b84629
f923084
ceb74e5
e5478f9
20c0e44
d7fa48a
abdd0de
f987dd2
46589d5
61a8530
48aa5a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,14 @@ import net.bible.android.control.versification.Scripture | |
import net.bible.android.view.activity.search.Search | ||
import net.bible.android.view.activity.search.SearchIndex | ||
import net.bible.android.view.activity.search.SearchResultsDto | ||
import net.bible.service.common.CommonUtils.limitTextLength | ||
import net.bible.service.sword.SwordContentFacade.getPlainText | ||
import net.bible.service.sword.SwordContentFacade.readOsisFragment | ||
import net.bible.service.sword.SwordContentFacade.search | ||
import net.bible.service.sword.SwordDocumentFacade | ||
import org.apache.commons.lang3.StringUtils | ||
import org.crosswire.jsword.book.Book | ||
import org.crosswire.jsword.book.BookCategory | ||
import org.crosswire.jsword.book.BookException | ||
import org.crosswire.jsword.book.basic.AbstractPassageBook | ||
import org.crosswire.jsword.book.sword.SwordBook | ||
|
@@ -38,6 +42,7 @@ import org.crosswire.jsword.index.lucene.LuceneIndex | |
import org.crosswire.jsword.index.search.SearchType | ||
import org.crosswire.jsword.passage.Key | ||
import org.crosswire.jsword.passage.Verse | ||
import org.jdom2.Element | ||
import javax.inject.Inject | ||
|
||
/** Support for the document search functionality | ||
|
@@ -52,6 +57,7 @@ class SearchControl @Inject constructor( | |
) | ||
{ | ||
private val isSearchShowingScripture = true | ||
var isStrongsSearch: Boolean = false | ||
|
||
enum class SearchBibleSection { | ||
OT, NT, CURRENT_BOOK, ALL | ||
|
@@ -95,11 +101,33 @@ class SearchControl @Inject constructor( | |
"-" | ||
} | ||
|
||
fun decorateSearchString(searchString: String, searchType: SearchType, bibleSection: SearchBibleSection, currentBookName: String?): String { | ||
val cleanSearchString = cleanSearchString(searchString) | ||
fun decorateSearchString(searchString: String, searchType: SearchType, bibleSection: SearchBibleSection, currentBookName: String?, | ||
includeAllEndings: Boolean=false, fuzzySearchAccuracy: Double? = null, proximityWords: Int? = null, | ||
strongs: Char? = null): String { | ||
var cleanSearchString = cleanSearchString(searchString) | ||
isStrongsSearch = strongs != null | ||
if (includeAllEndings || isStrongsSearch || fuzzySearchAccuracy != null) { | ||
var newSearchString = "" | ||
val wordArray: List<String> = cleanSearchString.split(" ") | ||
for (it in wordArray) { | ||
var decoratedWord = it | ||
if (includeAllEndings) decoratedWord += "* " | ||
if (isStrongsSearch) decoratedWord = "strong:$strongs$decoratedWord " | ||
if (fuzzySearchAccuracy != null) { | ||
val fuzzySearchAccuracyAdjusted = if (fuzzySearchAccuracy.equals(1.0)) 0.99 else fuzzySearchAccuracy | ||
decoratedWord += "~%.2f ".format(fuzzySearchAccuracyAdjusted) | ||
} | ||
newSearchString += decoratedWord | ||
} | ||
cleanSearchString = newSearchString.trim() | ||
} | ||
|
||
if (proximityWords != null) { | ||
cleanSearchString = "\"$cleanSearchString\"~$proximityWords" | ||
} | ||
|
||
// add search type (all/any/phrase) to search string | ||
var decorated: String = searchType.decorate(cleanSearchString) | ||
var decorated = searchType.decorate(cleanSearchString) | ||
originalSearchString = decorated | ||
|
||
// add bible section limitation to search text | ||
|
@@ -139,6 +167,43 @@ class SearchControl @Inject constructor( | |
return searchResults | ||
} | ||
|
||
fun getSearchResultVerseText(key: Key?): String { | ||
agrogers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// There is similar functionality in BookmarkControl | ||
// This is much slower than 'getSearchResultVerseElement'. Why? In the old version this was VERY fast. | ||
var verseText = "" | ||
try { | ||
val doc = windowControl.activeWindowPageManager.currentPage.currentDocument | ||
val cat = doc!!.bookCategory | ||
verseText = if (cat == BookCategory.BIBLE || cat == BookCategory.COMMENTARY) { | ||
getPlainText(doc, key) | ||
} else { | ||
val bible = windowControl.activeWindowPageManager.currentBible.currentDocument!! | ||
getPlainText(bible, key) | ||
} | ||
verseText = limitTextLength(verseText)!! | ||
} catch (e: Exception) { | ||
Log.e(TAG, "Error getting verse text", e) | ||
} | ||
return verseText | ||
} | ||
|
||
fun getSearchResultVerseElement(key: Key?): Element { | ||
// There is similar functionality in BookmarkControl | ||
var xmlVerse:Element? = null | ||
try { | ||
val doc = windowControl.activeWindowPageManager.currentPage.currentDocument | ||
val cat = doc!!.bookCategory | ||
xmlVerse = if (cat == BookCategory.BIBLE || cat == BookCategory.COMMENTARY) { | ||
readOsisFragment(doc, key) | ||
} else { | ||
val bible = windowControl.activeWindowPageManager.currentBible.currentDocument!! | ||
readOsisFragment(bible, key) | ||
} | ||
} catch (e: Exception) { | ||
Log.e(TAG, "Error getting verse text", e) | ||
} | ||
return xmlVerse!! | ||
} | ||
/** double spaces, :, and leading or trailing space cause lucene errors | ||
*/ | ||
private fun cleanSearchString(search: String): String { | ||
|
@@ -212,7 +277,7 @@ class SearchControl @Inject constructor( | |
const val TARGET_DOCUMENT = "TargetDocument" | ||
private const val STRONG_COLON_STRING = LuceneIndex.FIELD_STRONG + ":" | ||
private const val STRONG_COLON_STRING_PLACE_HOLDER = LuceneIndex.FIELD_STRONG + "COLON" | ||
const val MAX_SEARCH_RESULTS = 1000 | ||
const val MAX_SEARCH_RESULTS = 10000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite a lot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we need to limit it at all. The most hits i got was about 4000 for some common words. The search itself is very fast. Even big searches in its current form were acceptable (but slow) for me. The complete search results are valuable now because of the stats. My suggestions it make it very large. |
||
private const val TAG = "SearchControl" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this temporary (2 search results activities)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. I don't understand much about the manifest :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, we have now SearchResults, and MySearchResults. I think SearchResults is deprecated by MySearchResults. End result should be that we remove old SearchResults and rename MySearchResults -> SearchResults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sure i had answered this somewhere else. Yes, MySearchResults is a duplicate. The old one could be removed.