use of org.crosswire.jsword.passage.VerseKey in project step by STEPBible.
the class SubjectEntryServiceImpl method trimResultsToInputSearchRange.
/**
* Reduces the results so far to what is contained in the v11n
*
* @param inputVersion input version
* @param limitingScopeReference the limiting scope
* @param resultsInKJV the results retrieved so far.
*/
private void trimResultsToInputSearchRange(final String inputVersion, final String limitingScopeReference, final Key resultsInKJV) {
if (StringUtils.isNotBlank(limitingScopeReference)) {
final Book limitingBook;
limitingBook = this.versificationService.getBookFromVersion(inputVersion);
try {
final Key key = KeyUtil.getPassage(limitingBook.getKey(limitingScopeReference));
// now map to the KJV versification
Passage p = VersificationsMapper.instance().map(KeyUtil.getPassage(key), ((VerseKey) resultsInKJV).getVersification());
// now convert retain against existing resultsInKJV
resultsInKJV.retainAll(p);
} catch (NoSuchKeyException ex) {
throw new TranslatedException(ex, "invalid_reference_in_book", limitingScopeReference, limitingBook.getInitials());
}
}
}
use of org.crosswire.jsword.passage.VerseKey in project step by STEPBible.
the class SubjectEntryServiceImpl method getCombinedBookScope.
/**
* Gets a key in the KJV versification that represents the total combined key for all search resutls.
*
* @param inputVersions the input version the kjv versified keys
* @return
*/
private Passage getCombinedBookScope(String[] inputVersions) {
final Versification bestVersification = this.versificationService.getVersificationForVersion(JSwordPassageService.BEST_VERSIFICATION);
Passage range = new RangedPassage(bestVersification);
for (final String v : inputVersions) {
final Book bookFromVersion = this.versificationService.getBookFromVersion(v);
final VerseKey scope = bookFromVersion.getBookMetaData().getScope();
range.addAll(VersificationsMapper.instance().map(KeyUtil.getPassage(scope), bestVersification));
}
return range;
}
use of org.crosswire.jsword.passage.VerseKey in project step by STEPBible.
the class SubjectSearchServiceImpl method searchSimple.
/**
* runs a simple subject search
*
* @param sq the search query
* @return the results
*/
private SearchResult searchSimple(final SearchQuery sq) {
// ensure we're using the latest range
final IndividualSearch currentSearch = sq.getCurrentSearch();
currentSearch.setQuery(currentSearch.getQuery(), true);
final String[] originalVersions = currentSearch.getVersions();
final String[] searchableVersions = prepareSearchForHeadings(sq);
final Key allTopics = this.jswordSearch.searchKeys(sq);
// we will need to restrict the results by the scope of the versions, in the ESV v11n
final Passage maxScope = getScopeForVersions(originalVersions);
allTopics.retainAll(VersificationsMapper.instance().map(maxScope, ((VerseKey) allTopics).getVersification()));
SearchResult resultsAsHeadings = getResultsAsHeadings(sq, searchableVersions, allTopics);
cleanUpSearchFromHeadingsSearch(sq, originalVersions);
return resultsAsHeadings;
}
use of org.crosswire.jsword.passage.VerseKey in project step by STEPBible.
the class ReferenceSuggestionServiceImpl method getExactTerms.
@Override
public BookName[] getExactTerms(final SuggestionContext context, final int max, final boolean popularSort) {
final String masterBook = getDefaultedVersion(context);
final Book master = this.versificationService.getBookFromVersion(masterBook);
final Versification masterV11n = this.versificationService.getVersificationForVersion(masterBook);
final String input = prepInput(context.getInput());
try {
Key k = master.getKey(input);
if (k != null) {
// check this book actually contains this key, based on the scope...
if (!JSwordUtils.containsAny(master, k)) {
return new BookName[0];
// return getExactRange(input);
}
BookName bk;
if (k instanceof VerseKey) {
final VerseKey verseKey = (VerseKey) k;
final boolean wholeBook = isBook(masterV11n, verseKey);
if (wholeBook) {
final BibleBook book = ((Verse) verseKey.iterator().next()).getBook();
bk = getBookFromBibleBook(book, masterV11n);
} else {
bk = new BookName(verseKey.getName(), verseKey.getName(), BookName.Section.PASSAGE, wholeBook, ((Verse) verseKey.iterator().next()).getBook(), k.getOsisRef());
}
return new BookName[] { bk };
} else {
return new BookName[] { new BookName(k.getName(), k.getName(), BookName.Section.OTHER_NON_BIBLICAL, false, k.getOsisRef()) };
}
}
} catch (NoSuchKeyException ex) {
// silently fail
}
// return getExactRange(input);
return new BookName[0];
}
Aggregations