forked from openlp/openlp
text search for bibles
This commit is contained in:
commit
fa68d0d9ff
@ -75,7 +75,7 @@ def parse_reference(reference):
|
||||
7 None|[0-9]+|end None or the end of the second verse range.
|
||||
|
||||
The reference list is a list of tuples, with each tuple structured like
|
||||
this::
|
||||
this:
|
||||
(book, chapter, start_verse, end_verse)
|
||||
|
||||
``reference``
|
||||
|
@ -64,10 +64,10 @@ class Verse(BaseModel):
|
||||
|
||||
def init_schema(url):
|
||||
"""
|
||||
Setup a bible database connection and initialise the database schema
|
||||
Setup a bible database connection and initialise the database schema.
|
||||
|
||||
``url``
|
||||
The database to setup
|
||||
The database to setup.
|
||||
"""
|
||||
session, metadata = init_db(url)
|
||||
|
||||
@ -240,7 +240,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
and the value is the verse text.
|
||||
"""
|
||||
log.debug(u'create_chapter %s,%s', book_id, chapter)
|
||||
#text list has book and chapter as first two elements of the array
|
||||
# text list has book and chapter as first two elements of the array
|
||||
for verse_number, verse_text in textlist.iteritems():
|
||||
verse = Verse.populate(
|
||||
book_id = book_id,
|
||||
@ -281,23 +281,23 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def create_meta(self, key, value):
|
||||
"""
|
||||
Utility method to save BibleMeta objects in a Bible database
|
||||
Utility method to save BibleMeta objects in a Bible database.
|
||||
|
||||
``key``
|
||||
The key for this instance
|
||||
The key for this instance.
|
||||
|
||||
``value``
|
||||
The value for this instance
|
||||
The value for this instance.
|
||||
"""
|
||||
log.debug(u'save_meta %s/%s', key, value)
|
||||
self.save_object(BibleMeta.populate(key=key, value=value))
|
||||
|
||||
def get_book(self, book):
|
||||
"""
|
||||
Return a book object from the database
|
||||
Return a book object from the database.
|
||||
|
||||
``book``
|
||||
The name of the book to return
|
||||
The name of the book to return.
|
||||
"""
|
||||
log.debug(u'BibleDb.get_book("%s")', book)
|
||||
db_book = self.get_object_filtered(Book, Book.name.like(book + u'%'))
|
||||
@ -320,14 +320,14 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
``reference_list``
|
||||
This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format::
|
||||
a list of tuples, with the following format:
|
||||
|
||||
(book, chapter, start_verse, end_verse)
|
||||
|
||||
Therefore, when you are looking for multiple items, simply break
|
||||
them up into references like this, bundle them into a list. This
|
||||
function then runs through the list, and returns an amalgamated
|
||||
list of ``Verse`` objects. For example::
|
||||
list of ``Verse`` objects. For example:
|
||||
|
||||
[(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)]
|
||||
"""
|
||||
@ -353,9 +353,9 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
QtGui.QMessageBox.information(self.bible_plugin.mediaItem,
|
||||
translate('BiblesPlugin.BibleDB', 'Book not found'),
|
||||
translate('BiblesPlugin.BibleDB', 'The book you requested '
|
||||
'could not be found in this bible. Please check your '
|
||||
'spelling and that this is a complete bible not just '
|
||||
'one testament.'))
|
||||
'could not be found in this bible. Please check your '
|
||||
'spelling and that this is a complete bible not just '
|
||||
'one testament.'))
|
||||
return verse_list
|
||||
|
||||
def verse_search(self, text):
|
||||
@ -387,10 +387,10 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def get_chapter_count(self, book):
|
||||
"""
|
||||
Return the number of chapters in a book
|
||||
Return the number of chapters in a book.
|
||||
|
||||
``book``
|
||||
The book to get the chapter count for
|
||||
The book to get the chapter count for.
|
||||
"""
|
||||
log.debug(u'BibleDB.get_chapter_count("%s")', book)
|
||||
count = self.session.query(Verse.chapter).join(Book)\
|
||||
@ -403,13 +403,13 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def get_verse_count(self, book, chapter):
|
||||
"""
|
||||
Return the number of verses in a chapter
|
||||
Return the number of verses in a chapter.
|
||||
|
||||
``book``
|
||||
The book containing the chapter
|
||||
The book containing the chapter.
|
||||
|
||||
``chapter``
|
||||
The chapter to get the verse count for
|
||||
The chapter to get the verse count for.
|
||||
"""
|
||||
log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter)
|
||||
count = self.session.query(Verse).join(Book)\
|
||||
@ -423,7 +423,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
|
||||
def dump_bible(self):
|
||||
"""
|
||||
Utility debugging method to dump the contents of a bible
|
||||
Utility debugging method to dump the contents of a bible.
|
||||
"""
|
||||
log.debug(u'.........Dumping Bible Database')
|
||||
log.debug('...............................Books ')
|
||||
|
@ -187,16 +187,16 @@ class BGExtract(object):
|
||||
|
||||
def get_bible_chapter(self, version, bookname, chapter):
|
||||
"""
|
||||
Access and decode bibles via the BibleGateway website
|
||||
Access and decode bibles via the BibleGateway website.
|
||||
|
||||
``version``
|
||||
The version of the bible like 31 for New International version
|
||||
The version of the bible like 31 for New International version.
|
||||
|
||||
``bookname``
|
||||
Name of the Book
|
||||
Name of the Book.
|
||||
|
||||
``chapter``
|
||||
Chapter number
|
||||
Chapter number.
|
||||
"""
|
||||
log.debug(u'get_bible_chapter %s, %s, %s', version, bookname, chapter)
|
||||
url_params = urllib.urlencode(
|
||||
@ -298,13 +298,13 @@ class CWExtract(object):
|
||||
versetext = versetext + part
|
||||
elif part and part.attrMap and \
|
||||
(part.attrMap[u'class'] == u'WordsOfChrist' or \
|
||||
part.attrMap[u'class'] == u'strongs'):
|
||||
part.attrMap[u'class'] == u'strongs'):
|
||||
for subpart in part.contents:
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
if isinstance(subpart, NavigableString):
|
||||
versetext = versetext + subpart
|
||||
elif subpart and subpart.attrMap and \
|
||||
subpart.attrMap[u'class'] == u'strongs':
|
||||
subpart.attrMap[u'class'] == u'strongs':
|
||||
for subsub in subpart.contents:
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
if isinstance(subsub, NavigableString):
|
||||
@ -382,14 +382,14 @@ class HTTPBible(BibleDB):
|
||||
|
||||
``reference_list``
|
||||
This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format::
|
||||
a list of tuples, with the following format:
|
||||
|
||||
(book, chapter, start_verse, end_verse)
|
||||
|
||||
Therefore, when you are looking for multiple items, simply break
|
||||
them up into references like this, bundle them into a list. This
|
||||
function then runs through the list, and returns an amalgamated
|
||||
list of ``Verse`` objects. For example::
|
||||
list of ``Verse`` objects. For example:
|
||||
|
||||
[(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)]
|
||||
"""
|
||||
@ -428,7 +428,7 @@ class HTTPBible(BibleDB):
|
||||
|
||||
def get_chapter(self, book, chapter):
|
||||
"""
|
||||
Receive the request and call the relevant handler methods
|
||||
Receive the request and call the relevant handler methods.
|
||||
"""
|
||||
log.debug(u'get_chapter %s, %s', book, chapter)
|
||||
log.debug(u'source = %s', self.download_source)
|
||||
|
@ -137,7 +137,7 @@ class BibleManager(object):
|
||||
name = bible.get_name()
|
||||
log.debug(u'Bible Name: "%s"', name)
|
||||
self.db_cache[name] = bible
|
||||
# look to see if lazy load bible exists and get create getter.
|
||||
# Look to see if lazy load bible exists and get create getter.
|
||||
source = self.db_cache[name].get_object(BibleMeta,
|
||||
u'download source')
|
||||
if source:
|
||||
@ -204,7 +204,7 @@ class BibleManager(object):
|
||||
|
||||
def get_chapter_count(self, bible, book):
|
||||
"""
|
||||
Returns the number of Chapters for a given book
|
||||
Returns the number of Chapters for a given book.
|
||||
"""
|
||||
log.debug(u'get_book_chapter_count %s', book)
|
||||
return self.db_cache[bible].get_chapter_count(book)
|
||||
@ -212,7 +212,7 @@ class BibleManager(object):
|
||||
def get_verse_count(self, bible, book, chapter):
|
||||
"""
|
||||
Returns all the number of verses for a given
|
||||
book and chapterMaxBibleBookVerses
|
||||
book and chapterMaxBibleBookVerses.
|
||||
"""
|
||||
log.debug(u'BibleManager.get_verse_count("%s", "%s", %s)',
|
||||
bible, book, chapter)
|
||||
@ -238,6 +238,10 @@ class BibleManager(object):
|
||||
- Genesis 1:1-10,2:1-10
|
||||
"""
|
||||
log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext)
|
||||
# if type(versetext) is list:
|
||||
# reflist = versetext
|
||||
# else:
|
||||
# reflist = parse_reference(versetext)
|
||||
reflist = parse_reference(versetext)
|
||||
if reflist:
|
||||
return self.db_cache[bible].get_verses(reflist)
|
||||
@ -254,12 +258,33 @@ class BibleManager(object):
|
||||
'Book Chapter:Verse-Verse\n'
|
||||
'Book Chapter:Verse-Verse,Verse-Verse\n'
|
||||
'Book Chapter:Verse-Verse,Chapter:Verse-Verse\n'
|
||||
'Book Chapter:Verse-Chapter:Verse\n'))
|
||||
'Book Chapter:Verse-Chapter:Verse'))
|
||||
return None
|
||||
|
||||
def verse_search(self, bible, text):
|
||||
"""
|
||||
``bible``
|
||||
The bible to seach in.
|
||||
|
||||
``text``
|
||||
The text to search for.
|
||||
"""
|
||||
log.debug(u'BibleManager.verse_search("%s", "%s")', bible, text)
|
||||
if text:
|
||||
return self.db_cache[bible].verse_search(text)
|
||||
else:
|
||||
QtGui.QMessageBox.information(self.parent.mediaItem,
|
||||
translate('BiblesPlugin.BibleManager',
|
||||
'Scripture Reference Error'),
|
||||
translate('BiblesPlugin.BibleManager', 'You did not enter a '
|
||||
'search keyword.\nYou can seperate different keywords by a space'
|
||||
' to search for all of your keywords and can seperate them by a'
|
||||
' comma to search for one of them.'))
|
||||
return None
|
||||
|
||||
def save_meta_data(self, bible, version, copyright, permissions):
|
||||
"""
|
||||
Saves the bibles meta data
|
||||
Saves the bibles meta data.
|
||||
"""
|
||||
log.debug(u'save_meta data %s,%s, %s,%s',
|
||||
bible, version, copyright, permissions)
|
||||
@ -269,14 +294,14 @@ class BibleManager(object):
|
||||
|
||||
def get_meta_data(self, bible, key):
|
||||
"""
|
||||
Returns the meta data for a given key
|
||||
Returns the meta data for a given key.
|
||||
"""
|
||||
log.debug(u'get_meta %s,%s', bible, key)
|
||||
return self.db_cache[bible].get_object(BibleMeta, key)
|
||||
|
||||
def exists(self, name):
|
||||
"""
|
||||
Check cache to see if new bible
|
||||
Check cache to see if new bible.
|
||||
"""
|
||||
if not isinstance(name, unicode):
|
||||
name = unicode(name)
|
||||
|
@ -497,6 +497,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
|
||||
def onAdvancedSearchButton(self):
|
||||
log.debug(u'Advanced Search Button pressed')
|
||||
self.AdvancedSearchButton.setEnabled(False)
|
||||
bible = unicode(self.AdvancedVersionComboBox.currentText())
|
||||
dual_bible = unicode(self.AdvancedSecondBibleComboBox.currentText())
|
||||
book = unicode(self.AdvancedBookComboBox.currentText())
|
||||
@ -529,16 +530,33 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.displayResults(bible, dual_bible)
|
||||
else:
|
||||
self.displayResults(bible, dual_bible)
|
||||
self.AdvancedSearchButton.setEnabled(True)
|
||||
|
||||
def onQuickSearchButton(self):
|
||||
log.debug(u'Quick Search Button pressed')
|
||||
self.QuickSearchButton.setEnabled(False)
|
||||
bible = unicode(self.QuickVersionComboBox.currentText())
|
||||
dual_bible = unicode(self.QuickSecondBibleComboBox.currentText())
|
||||
text = unicode(self.QuickSearchEdit.text())
|
||||
self.search_results = self.parent.manager.get_verses(bible, text)
|
||||
if dual_bible:
|
||||
self.dual_search_results = self.parent.manager.get_verses(
|
||||
dual_bible, text)
|
||||
if self.QuickSearchComboBox.currentIndex() == 0: # Verse Search
|
||||
self.search_results = self.parent.manager.get_verses(bible, text)
|
||||
if dual_bible and self.search_results:
|
||||
self.dual_search_results = self.parent.manager.get_verses(
|
||||
dual_bible, text)
|
||||
else: # Text Search
|
||||
self.search_results = self.parent.manager.verse_search(bible, text)
|
||||
if dual_bible and self.search_results:
|
||||
# text = []
|
||||
# for verse in self.search_results:
|
||||
# text.append((verse.book.name, verse.chapter, verse.verse,
|
||||
# verse.verse))
|
||||
# self.dual_search_results = self.parent.manager.get_verses(
|
||||
# dual_bible, text)
|
||||
for count, verse in enumerate(self.search_results):
|
||||
text = u'%s %s:%s' % (verse.book.name, verse.chapter,
|
||||
verse.verse)
|
||||
self.dual_search_results[count] = self.parent.manager.\
|
||||
get_verses(dual_bible, text, text)[0]
|
||||
if self.ClearQuickSearchComboBox.currentIndex() == 0:
|
||||
self.listView.clear()
|
||||
if self.listView.count() != 0 and self.search_results:
|
||||
@ -558,6 +576,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.displayResults(bible, dual_bible)
|
||||
elif self.search_results:
|
||||
self.displayResults(bible, dual_bible)
|
||||
self.QuickSearchButton.setEnabled(True)
|
||||
|
||||
def displayResults(self, bible, dual_bible=u''):
|
||||
"""
|
||||
@ -566,16 +585,16 @@ class BibleMediaItem(MediaManagerItem):
|
||||
"""
|
||||
version = self.parent.manager.get_meta_data(bible, u'Version')
|
||||
copyright = self.parent.manager.get_meta_data(bible, u'Copyright')
|
||||
permission = self.parent.manager.get_meta_data(bible, u'Permissions')
|
||||
permissions = self.parent.manager.get_meta_data(bible, u'Permissions')
|
||||
if dual_bible:
|
||||
dual_version = self.parent.manager.get_meta_data(dual_bible,
|
||||
u'Version')
|
||||
dual_copyright = self.parent.manager.get_meta_data(dual_bible,
|
||||
u'Copyright')
|
||||
dual_permission = self.parent.manager.get_meta_data(dual_bible,
|
||||
dual_permissions = self.parent.manager.get_meta_data(dual_bible,
|
||||
u'Permissions')
|
||||
if not dual_permission:
|
||||
dual_permission = u''
|
||||
if not dual_permissions:
|
||||
dual_permissions = u''
|
||||
# We count the number of rows which are maybe already present.
|
||||
start_count = self.listView.count()
|
||||
for count, verse in enumerate(self.search_results):
|
||||
@ -587,12 +606,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
'bible': QtCore.QVariant(bible),
|
||||
'version': QtCore.QVariant(version.value),
|
||||
'copyright': QtCore.QVariant(copyright.value),
|
||||
'permission': QtCore.QVariant(permission.value),
|
||||
'permissions': QtCore.QVariant(permissions.value),
|
||||
'text': QtCore.QVariant(verse.text),
|
||||
'dual_bible': QtCore.QVariant(dual_bible),
|
||||
'dual_version': QtCore.QVariant(dual_version.value),
|
||||
'dual_copyright': QtCore.QVariant(dual_copyright.value),
|
||||
'dual_permission': QtCore.QVariant(dual_permission.value),
|
||||
'dual_permissions': QtCore.QVariant(dual_permissions.value),
|
||||
'dual_text': QtCore.QVariant(
|
||||
self.dual_search_results[count].text)
|
||||
}
|
||||
@ -607,12 +626,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
'bible': QtCore.QVariant(bible),
|
||||
'version': QtCore.QVariant(version.value),
|
||||
'copyright': QtCore.QVariant(copyright.value),
|
||||
'permission': QtCore.QVariant(permission.value),
|
||||
'permissions': QtCore.QVariant(permissions.value),
|
||||
'text': QtCore.QVariant(verse.text),
|
||||
'dual_bible': QtCore.QVariant(u''),
|
||||
'dual_version': QtCore.QVariant(u''),
|
||||
'dual_copyright': QtCore.QVariant(u''),
|
||||
'dual_permission': QtCore.QVariant(u''),
|
||||
'dual_permissions': QtCore.QVariant(u''),
|
||||
'dual_text': QtCore.QVariant(u'')
|
||||
}
|
||||
bible_text = u' %s %d:%d (%s)' % (verse.book.name,
|
||||
@ -658,20 +677,20 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bible = self._decodeQtObject(bitem, 'bible')
|
||||
version = self._decodeQtObject(bitem, 'version')
|
||||
copyright = self._decodeQtObject(bitem, 'copyright')
|
||||
permission = self._decodeQtObject(bitem, 'permission')
|
||||
permissions = self._decodeQtObject(bitem, 'permissions')
|
||||
text = self._decodeQtObject(bitem, 'text')
|
||||
dual_bible = self._decodeQtObject(bitem, 'dual_bible')
|
||||
dual_version = self._decodeQtObject(bitem, 'dual_version')
|
||||
dual_copyright = self._decodeQtObject(bitem, 'dual_copyright')
|
||||
dual_permission = self._decodeQtObject(bitem, 'dual_permission')
|
||||
dual_permissions = self._decodeQtObject(bitem, 'dual_permissions')
|
||||
dual_text = self._decodeQtObject(bitem, 'dual_text')
|
||||
verse_text = self.formatVerse(old_chapter, chapter, verse)
|
||||
footer = u'%s (%s %s %s)' % (book, version, copyright, permission)
|
||||
footer = u'%s (%s %s %s)' % (book, version, copyright, permissions)
|
||||
if footer not in raw_footer:
|
||||
raw_footer.append(footer)
|
||||
if dual_bible:
|
||||
footer = u'%s (%s %s %s)' % (book, dual_version, dual_copyright,
|
||||
dual_permission)
|
||||
dual_permissions)
|
||||
if footer not in raw_footer:
|
||||
raw_footer.append(footer)
|
||||
bible_text = u'%s %s\n\n%s %s' % (verse_text, text, verse_text,
|
||||
@ -702,19 +721,16 @@ class BibleMediaItem(MediaManagerItem):
|
||||
if bible_text:
|
||||
raw_slides.append(bible_text)
|
||||
bible_text = u''
|
||||
# Service Item: Capabilities
|
||||
if self.parent.settings_tab.layout_style == 2 and not dual_bible:
|
||||
# Split the line but do not replace line breaks in renderer.
|
||||
service_item.add_capability(ItemCapabilities.NoLineBreaks)
|
||||
service_item.add_capability(ItemCapabilities.AllowsPreview)
|
||||
service_item.add_capability(ItemCapabilities.AllowsLoop)
|
||||
# Service Item: Title
|
||||
for title in raw_title:
|
||||
if not service_item.title:
|
||||
service_item.title = title
|
||||
else:
|
||||
service_item.title += u', ' + title
|
||||
# Service Item: Theme
|
||||
if len(self.parent.settings_tab.bible_theme) == 0:
|
||||
service_item.theme = None
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user