forked from openlp/openlp
In this merge:
Refactored the code for combined search. - Added: def on_quick_reference_search(self): and moved definition of reference search there. - Added: def on_quick_text_search(self): and moved definition of text search there. - Removed some un-needed code duplicates (Double finalizing, 3rd normalizing of mouse cursor) - Searching scripture ref with shorter than 3 char search is now possible (G1 = Genesis 1) Also removed “Search” from “Search Text or Reference…” since it does not fit the box properly.
This commit is contained in:
parent
447f7a9ead
commit
1d67072dfd
@ -312,7 +312,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
self.quick_search_edit.set_search_types([
|
self.quick_search_edit.set_search_types([
|
||||||
(BibleSearch.Combined, ':/bibles/bibles_search_combined.png',
|
(BibleSearch.Combined, ':/bibles/bibles_search_combined.png',
|
||||||
translate('BiblesPlugin.MediaItem', 'Text or Scripture Reference'),
|
translate('BiblesPlugin.MediaItem', 'Text or Scripture Reference'),
|
||||||
translate('BiblesPlugin.MediaItem', 'Search Text or Scripture Reference...')),
|
translate('BiblesPlugin.MediaItem', 'Text or Scripture Reference...')),
|
||||||
(BibleSearch.Reference, ':/bibles/bibles_search_reference.png',
|
(BibleSearch.Reference, ':/bibles/bibles_search_reference.png',
|
||||||
translate('BiblesPlugin.MediaItem', 'Scripture Reference'),
|
translate('BiblesPlugin.MediaItem', 'Scripture Reference'),
|
||||||
translate('BiblesPlugin.MediaItem', 'Search Scripture Reference...')),
|
translate('BiblesPlugin.MediaItem', 'Search Scripture Reference...')),
|
||||||
@ -652,6 +652,53 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
self.check_search_result()
|
self.check_search_result()
|
||||||
self.application.set_normal_cursor()
|
self.application.set_normal_cursor()
|
||||||
|
|
||||||
|
def on_quick_reference_search(self):
|
||||||
|
# We are doing a 'Reference Search'.
|
||||||
|
bible = self.quickVersionComboBox.currentText()
|
||||||
|
second_bible = self.quickSecondComboBox.currentText()
|
||||||
|
# Get input from field and replace '. ' with ''
|
||||||
|
text_direct = self.quick_search_edit.text()
|
||||||
|
text = text_direct.replace('. ', ' ')
|
||||||
|
if self.quick_search_edit.current_search_type() == BibleSearch.Reference:
|
||||||
|
self.search_results = self.plugin.manager.get_verses(bible, text)
|
||||||
|
else:
|
||||||
|
self.search_results = self.plugin.manager.get_verses_combined(bible, text)
|
||||||
|
if second_bible and self.search_results:
|
||||||
|
self.second_search_results = \
|
||||||
|
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
||||||
|
|
||||||
|
def on_quick_text_search(self):
|
||||||
|
# We are doing a 'Text Search'.
|
||||||
|
bible = self.quickVersionComboBox.currentText()
|
||||||
|
second_bible = self.quickSecondComboBox.currentText()
|
||||||
|
text = self.quick_search_edit.text()
|
||||||
|
self.application.set_busy_cursor()
|
||||||
|
bibles = self.plugin.manager.get_bibles()
|
||||||
|
self.search_results = self.plugin.manager.verse_search(bible, second_bible, text)
|
||||||
|
if second_bible and self.search_results:
|
||||||
|
text = []
|
||||||
|
new_search_results = []
|
||||||
|
count = 0
|
||||||
|
passage_not_found = False
|
||||||
|
for verse in self.search_results:
|
||||||
|
db_book = bibles[second_bible].get_book_by_book_ref_id(verse.book.book_reference_id)
|
||||||
|
if not db_book:
|
||||||
|
log.debug('Passage "%s %d:%d" not found in Second Bible' %
|
||||||
|
(verse.book.name, verse.chapter, verse.verse))
|
||||||
|
passage_not_found = True
|
||||||
|
count += 1
|
||||||
|
continue
|
||||||
|
new_search_results.append(verse)
|
||||||
|
text.append((verse.book.book_reference_id, verse.chapter, verse.verse, verse.verse))
|
||||||
|
if passage_not_found:
|
||||||
|
self.main_window.information_message(
|
||||||
|
translate('BiblesPlugin.MediaItem', 'Information'),
|
||||||
|
translate('BiblesPlugin.MediaItem', 'The second Bible does not contain all the verses '
|
||||||
|
'that are in the main Bible. Only verses found in both Bibles will be shown. %d '
|
||||||
|
'verses have not been included in the results.') % count)
|
||||||
|
self.search_results = new_search_results
|
||||||
|
self.second_search_results = bibles[second_bible].get_verses(text)
|
||||||
|
|
||||||
def on_quick_search_button(self):
|
def on_quick_search_button(self):
|
||||||
"""
|
"""
|
||||||
Does a quick search and saves the search results. Quick search can be:
|
Does a quick search and saves the search results. Quick search can be:
|
||||||
@ -662,94 +709,28 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
self.application.process_events()
|
self.application.process_events()
|
||||||
bible = self.quickVersionComboBox.currentText()
|
bible = self.quickVersionComboBox.currentText()
|
||||||
second_bible = self.quickSecondComboBox.currentText()
|
second_bible = self.quickSecondComboBox.currentText()
|
||||||
# Get input from field and replace '. ' with ''
|
text = self.quick_search_edit.text()
|
||||||
text_direct = self.quick_search_edit.text()
|
|
||||||
text = text_direct.replace('. ', ' ')
|
|
||||||
# This will check if field has any '.' and removes them. Eg. Gen. 1 = Gen 1 = Genesis 1
|
# This will check if field has any '.' and removes them. Eg. Gen. 1 = Gen 1 = Genesis 1
|
||||||
if self.quick_search_edit.current_search_type() == BibleSearch.Reference:
|
if self.quick_search_edit.current_search_type() == BibleSearch.Reference:
|
||||||
# We are doing a 'Reference Search'.
|
# We are doing a 'Reference Search'. (Get script from def on_quick_reference_search)
|
||||||
self.search_results = self.plugin.manager.get_verses(bible, text)
|
self.on_quick_reference_search()
|
||||||
if second_bible and self.search_results:
|
|
||||||
self.second_search_results = \
|
|
||||||
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
|
||||||
elif self.quick_search_edit.current_search_type() == BibleSearch.Text:
|
elif self.quick_search_edit.current_search_type() == BibleSearch.Text:
|
||||||
# We are doing a 'Text Search'.
|
# We are doing a 'Text Search'. (Get script from def on_quick_text_search)
|
||||||
self.application.set_busy_cursor()
|
self.on_quick_text_search()
|
||||||
bibles = self.plugin.manager.get_bibles()
|
# Combined search, starting with reference search.
|
||||||
self.search_results = self.plugin.manager.verse_search(bible, second_bible, text)
|
|
||||||
if second_bible and self.search_results:
|
|
||||||
text = []
|
|
||||||
new_search_results = []
|
|
||||||
count = 0
|
|
||||||
passage_not_found = False
|
|
||||||
for verse in self.search_results:
|
|
||||||
db_book = bibles[second_bible].get_book_by_book_ref_id(verse.book.book_reference_id)
|
|
||||||
if not db_book:
|
|
||||||
log.debug('Passage "%s %d:%d" not found in Second Bible' %
|
|
||||||
(verse.book.name, verse.chapter, verse.verse))
|
|
||||||
passage_not_found = True
|
|
||||||
count += 1
|
|
||||||
continue
|
|
||||||
new_search_results.append(verse)
|
|
||||||
text.append((verse.book.book_reference_id, verse.chapter, verse.verse, verse.verse))
|
|
||||||
if passage_not_found:
|
|
||||||
self.main_window.information_message(
|
|
||||||
translate('BiblesPlugin.MediaItem', 'Information'),
|
|
||||||
translate('BiblesPlugin.MediaItem', 'The second Bible does not contain all the verses '
|
|
||||||
'that are in the main Bible. Only verses found in both Bibles will be shown. %d '
|
|
||||||
'verses have not been included in the results.') % count)
|
|
||||||
self.search_results = new_search_results
|
|
||||||
self.second_search_results = bibles[second_bible].get_verses(text)
|
|
||||||
# Combined search, starting with reference search (combined)
|
|
||||||
elif self.quick_search_edit.current_search_type() == BibleSearch.Combined:
|
elif self.quick_search_edit.current_search_type() == BibleSearch.Combined:
|
||||||
self.search_results = self.plugin.manager.get_verses_combined(bible, text)
|
self.on_quick_reference_search()
|
||||||
if second_bible and self.search_results:
|
|
||||||
self.second_search_results = \
|
|
||||||
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
|
||||||
# If keyword is shorter than 3 (not including spaces), message is given and search is finalized.
|
# If keyword is shorter than 3 (not including spaces), message is given and search is finalized.
|
||||||
# This needs to be here in order to avoid deadlock/duplicate errors.
|
# It's actually to find verses with less than 3 chars (Eg. G1 = Genesis 1) thus this error is not shown if
|
||||||
if len(text) - text.count(' ') < 3:
|
# any results are found. This check needs to be here in order to avoid duplicate errors.
|
||||||
|
if not self.search_results and len(text) - text.count(' ') < 3:
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
('%s' % UiStrings().BibleShortSearchTitle),
|
('%s' % UiStrings().BibleShortSearchTitle),
|
||||||
('%s' % UiStrings().BibleShortSearch))
|
('%s' % UiStrings().BibleShortSearch))
|
||||||
if not self.quickLockButton.isChecked():
|
|
||||||
self.list_view.clear()
|
|
||||||
if self.list_view.count() != 0 and self.search_results:
|
|
||||||
self.__check_second_bible(bible, second_bible)
|
|
||||||
elif self.search_results:
|
|
||||||
self.display_results(bible, second_bible)
|
|
||||||
self.quickSearchButton.setEnabled(True)
|
|
||||||
self.check_search_result()
|
|
||||||
self.application.set_normal_cursor()
|
|
||||||
# Text search starts here if no reference was found and keyword is longer than 2.
|
# Text search starts here if no reference was found and keyword is longer than 2.
|
||||||
# This is required in order to avoid duplicate error messages for short keywords.
|
# This is required in order to avoid duplicate error messages for short keywords.
|
||||||
if not self.search_results and len(text) - text.count(' ') > 2:
|
if not self.search_results and len(text) - text.count(' ') > 2:
|
||||||
self.application.set_busy_cursor()
|
self.on_quick_text_search()
|
||||||
bibles = self.plugin.manager.get_bibles()
|
|
||||||
self.search_results = self.plugin.manager.verse_search(bible, second_bible, text)
|
|
||||||
if second_bible and self.search_results:
|
|
||||||
text = []
|
|
||||||
new_search_results = []
|
|
||||||
count = 0
|
|
||||||
passage_not_found = False
|
|
||||||
for verse in self.search_results:
|
|
||||||
db_book = bibles[second_bible].get_book_by_book_ref_id(verse.book.book_reference_id)
|
|
||||||
if not db_book:
|
|
||||||
log.debug('Passage "%s %d:%d" not found in Second Bible' %
|
|
||||||
(verse.book.name, verse.chapter, verse.verse))
|
|
||||||
passage_not_found = True
|
|
||||||
count += 1
|
|
||||||
continue
|
|
||||||
new_search_results.append(verse)
|
|
||||||
text.append((verse.book.book_reference_id, verse.chapter, verse.verse, verse.verse))
|
|
||||||
if passage_not_found:
|
|
||||||
self.main_window.information_message(
|
|
||||||
translate('BiblesPlugin.MediaItem', 'Information'),
|
|
||||||
translate('BiblesPlugin.MediaItem', 'The second Bible does not contain all the verses '
|
|
||||||
'that are in the main Bible. Only verses found in both Bibles will be shown. %d '
|
|
||||||
'verses have not been included in the results.') % count)
|
|
||||||
self.search_results = new_search_results
|
|
||||||
self.second_search_results = bibles[second_bible].get_verses(text)
|
|
||||||
# If no Text or Reference is found, message is given.
|
# If no Text or Reference is found, message is given.
|
||||||
if not self.search_results:
|
if not self.search_results:
|
||||||
self.application.set_normal_cursor()
|
self.application.set_normal_cursor()
|
||||||
|
Loading…
Reference in New Issue
Block a user