[jsword-devel] Getting the global key list for a book

DM Smith dmsmith at crosswire.org
Fri Feb 15 13:22:25 MST 2013


That's what http://www.crosswire.org/tracker/browse/JS-246 is all about.

There are a good number of places that we get all the keys for a module. But the construction of the list is dumb.

The question is what do you want? Do you want all the possible keys in a versification? Or do you want the keys for the verses that are actually in a module?

If you only want chapters that exist, consider working off of Versification to get the book names and the chapters. For each chapter, get the number of verses and grab one (maybe verse 1 or one halfway into the chapter) on the assumption that if one exists then the rest do.


Calling book.contains(key) is what you want to do. It goes against the backend to determine whether the verse is in the module.

Don't call book.getGlobalKeyList(); We probably should deprecate the method. It is too easy to call it and it is very expensive for what it does.

I have a 3 day weekend and hope to finish the av11n work. It impacts this. Will probably add iterators for a versification.

In Him,
	DM



On Feb 15, 2013, at 2:14 PM, Chris Burrell <chris at burrell.me.uk> wrote:

> Hi all
> 
> getGlobalKeyList() seems to do a lot of work against the file system. 
> 
> I'm attempting to create a sitemap, which includes a URL to every chapter. Presumably getGlobalKeyList is what I want to ensure that I'm only displaying those chapters that exist. I was intending to do:
> 
> globalKeyList = getGlobalKeyList();
> for(each book in versification) {
>     myBookKey = book.getValidKey(book.getShortName())
>     myBookKey.retainAll(globalKeyList);
> 
>     if(myBookKey.getCardinality() > 0) {
>         outputSiteMapChapter();
>     }
> }
> 
> So for each version I call getGlobalKeyList(), but that in terms seem to make individual reads (through the contains()) method for every potential key in the versification.
> 
> public final Key getGlobalKeyList() {
>         if (global == null) {
>             Versification v11n = Versifications.instance().getVersification(versification);
>             global = keyf.createEmptyKeyList(v11n);
>             Key all = keyf.getGlobalKeyList(v11n);
>             for (Key key : all) {
>                 if (contains(key)) {
>                     global.addAll(key);
>                 }
>             }
>         }
>         return global;
> }
> 
> The contains() method above makes a backend call every time.
> 
> Isn't there a way to obtain the list of keys from the index? I'm not quite sure where the versification comes in here, or is it there simply to map the names of the keys to their positions in the index file? If so, can we simply read all keys in OT and NT, and check 
> 
> Doing this on GlobalKeyList() would also speed up index creation.
> 
> Finally, it seems contains() only works on a single key, or takes the first key/verse if it's a passage. Presumably that is correct?
> 
> Chris
> 
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel




More information about the jsword-devel mailing list