Search in sources :

Example 36 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class SubjectSearchServiceImpl method naveDocsToReference.

/**
 * Converts a set of nave documents to their reference equivalent
 *
 * @param extendedDocs
 * @return
 */
private Key naveDocsToReference(SearchQuery sq, EntityDoc[] extendedDocs) {
    String mainVersion = sq.getCurrentSearch().getVersions()[0];
    Book naveVersion = this.jSwordVersificationService.getBookFromVersion(JSwordPassageService.BEST_VERSIFICATION);
    Book bookFromVersion = this.jSwordVersificationService.getBookFromVersion(mainVersion);
    Key passageKey = null;
    for (EntityDoc d : extendedDocs) {
        String storedReferences = d.get(NAVE_STORED_REFERENCES);
        final Key key;
        try {
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            // NEEDS TO BE KJV
            key = naveVersion.getKey(storedReferences);
        } catch (Exception ex) {
            throw new StepInternalException("Stored references are unparseable in nave module: " + storedReferences);
        }
        if (passageKey == null) {
            passageKey = key;
        } else {
            passageKey.addAll(key);
        }
    }
    return passageKey;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Book(org.crosswire.jsword.book.Book) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) VerseKey(org.crosswire.jsword.passage.VerseKey) Key(org.crosswire.jsword.passage.Key) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) ParseException(org.apache.lucene.queryParser.ParseException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 37 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class SubjectSearchServiceImpl method getKeys.

@Override
public Key getKeys(SearchQuery sq) {
    switch(sq.getCurrentSearch().getType()) {
        case SUBJECT_SIMPLE:
            final String[] originalVersions = sq.getCurrentSearch().getVersions();
            prepareSearchForHeadings(sq);
            final Key allTopics = this.jswordSearch.searchKeys(sq);
            cleanUpSearchFromHeadingsSearch(sq, originalVersions);
            return allTopics;
        case SUBJECT_EXTENDED:
            return naveDocsToReference(sq, this.getNaveDocs(sq));
        case SUBJECT_FULL:
            return naveDocsToReference(sq, this.getExtendedNaveDocs(sq));
        case SUBJECT_RELATED:
            return naveDocsToReference(sq, getDocsByExpandedReferences(this.getInputReferenceForNaveSearch(sq.getCurrentSearch().getVersions(), sq.getCurrentSearch().getQuery()).getValue()));
        default:
            throw new StepInternalException("Unrecognized subject search");
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) VerseKey(org.crosswire.jsword.passage.VerseKey) Key(org.crosswire.jsword.passage.Key)

Example 38 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class JSwordModuleServiceImpl method getProgressOnIndexing.

@Override
public double getProgressOnIndexing(final String bookName) {
    notBlank(bookName, "The book name to be indexed was blank", SERVICE_VALIDATION_ERROR);
    if (isIndexed(bookName)) {
        return 1;
    }
    // not yet installed (or at least wasn't on the lines above, so check job list
    String longVersionName = this.versionResolver.getLongName(bookName);
    final Iterator<Progress> iterator = JobManager.iterator();
    while (iterator.hasNext()) {
        final Progress p = iterator.next();
        final String expectedJobName = format(CURRENT_BIBLE_INDEX_JOB, longVersionName);
        if (expectedJobName.equals(p.getJobName())) {
            if (p.isFinished()) {
                return 1;
            }
            return (double) p.getWork() / p.getTotalWork();
        }
    }
    // the job may have completed by now, while we did the search, so do a final check
    if (isIndexed(bookName)) {
        return 1;
    }
    throw new StepInternalException("An unknown error has occurred: the job has disappeared of the job list, " + "but the module is not installed");
}
Also used : Progress(org.crosswire.common.progress.Progress) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 39 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class JSwordSearchServiceImpl method mergeSearches.

/**
 * merges all search results together
 *
 * @param resultsPerVersion the results per version
 * @return the list of results
 */
private Key mergeSearches(final Map<String, Key> resultsPerVersion) {
    Key all = null;
    Versification allVersification = null;
    for (final Entry<String, Key> entry : resultsPerVersion.entrySet()) {
        final Key value = entry.getValue();
        LOGGER.debug("Sub-result-set [{}] has [{}] entries", entry.getKey(), value.getCardinality());
        if (all == null) {
            all = value;
            if (all instanceof VerseKey) {
                allVersification = ((VerseKey) all).getVersification();
            }
        } else {
            boolean valueIsVerseKey = value instanceof VerseKey;
            if (valueIsVerseKey && allVersification == null) {
                throw new StepInternalException("Trying to combine versified key with non-versified key.");
            }
            // i.e. and allVersification != null
            Key convertedKey = value;
            if (valueIsVerseKey) {
                final VerseKey versifiedResults = (VerseKey) value;
                final Passage versifiedPassageResults = KeyUtil.getPassage(versifiedResults);
                convertedKey = VersificationsMapper.instance().map(versifiedPassageResults, allVersification);
            }
            all.addAll(convertedKey);
        }
        LOGGER.debug("Combined result-set has [{}] entries", all.getCardinality());
    }
    return all;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Versification(org.crosswire.jsword.versification.Versification)

Example 40 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class TestEntityIndexWriterImpl method close.

@Override
public synchronized int close() {
    try {
        final IndexWriter ramWriter = getRamWriter();
        ramWriter.maybeMerge();
        ramWriter.optimize(true);
        ramWriter.close();
    } catch (final IOException e) {
        throw new StepInternalException("Unable to write to ram index", e);
    }
    return super.getNumEntriesInIndex();
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2