Search in sources :

Example 1 with VerseKey

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());
        }
    }
}
Also used : NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Book(org.crosswire.jsword.book.Book) Passage(org.crosswire.jsword.passage.Passage) RangedPassage(org.crosswire.jsword.passage.RangedPassage) Key(org.crosswire.jsword.passage.Key) VerseKey(org.crosswire.jsword.passage.VerseKey)

Example 2 with VerseKey

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;
}
Also used : RangedPassage(org.crosswire.jsword.passage.RangedPassage) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) Passage(org.crosswire.jsword.passage.Passage) RangedPassage(org.crosswire.jsword.passage.RangedPassage) VerseKey(org.crosswire.jsword.passage.VerseKey)

Example 3 with VerseKey

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;
}
Also used : IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) Passage(org.crosswire.jsword.passage.Passage) RangedPassage(org.crosswire.jsword.passage.RangedPassage) VerseKey(org.crosswire.jsword.passage.VerseKey) VerseKey(org.crosswire.jsword.passage.VerseKey) Key(org.crosswire.jsword.passage.Key)

Example 4 with VerseKey

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];
}
Also used : BibleBook(org.crosswire.jsword.versification.BibleBook) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) AbstractPassageBook(org.crosswire.jsword.book.basic.AbstractPassageBook) BookName(com.tyndalehouse.step.core.models.BookName) Versification(org.crosswire.jsword.versification.Versification) VerseKey(org.crosswire.jsword.passage.VerseKey) Key(org.crosswire.jsword.passage.Key) VerseKey(org.crosswire.jsword.passage.VerseKey) Verse(org.crosswire.jsword.passage.Verse)

Aggregations

VerseKey (org.crosswire.jsword.passage.VerseKey)4 Book (org.crosswire.jsword.book.Book)3 Key (org.crosswire.jsword.passage.Key)3 Passage (org.crosswire.jsword.passage.Passage)3 RangedPassage (org.crosswire.jsword.passage.RangedPassage)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)2 Versification (org.crosswire.jsword.versification.Versification)2 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 BookName (com.tyndalehouse.step.core.models.BookName)1 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)1 IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)1 AbstractPassageBook (org.crosswire.jsword.book.basic.AbstractPassageBook)1 Verse (org.crosswire.jsword.passage.Verse)1 BibleBook (org.crosswire.jsword.versification.BibleBook)1