Search in sources :

Example 6 with TranslatedException

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

the class SearchServiceImpl method lookupFromLexicon.

/**
 * Looks up the search criteria from the lexicon
 *
 * @param query the query
 * @return a list of strong numbers
 */
private Set<String> lookupFromLexicon(final String query) {
    // if we still have nothing, then look through the definitions
    final QueryParser parser = new QueryParser(Version.LUCENE_30, "accentedUnicode", this.definitions.getAnalyzer());
    Query parsed;
    try {
        parsed = parser.parse(QueryParser.escape(query));
    } catch (final ParseException e) {
        throw new TranslatedException(e, "search_invalid");
    }
    final EntityDoc[] results = this.definitions.search(parsed);
    final Set<String> matchedStrongs = new HashSet<String>();
    for (final EntityDoc d : results) {
        matchedStrongs.add(d.get(STRONG_NUMBER_FIELD));
    }
    return matchedStrongs;
}
Also used : QueryParser(org.apache.lucene.queryParser.QueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) Query(org.apache.lucene.search.Query) SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ParseException(org.apache.lucene.queryParser.ParseException) HashSet(java.util.HashSet)

Example 7 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException 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 8 with TranslatedException

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

the class SubjectSearchServiceImpl method searchByMultipleReferences.

@Override
public SearchResult searchByMultipleReferences(final String[] versions, final String references) {
    final StringAndCount allReferencesAndCounts = this.getInputReferenceForNaveSearch(versions, references);
    int count = allReferencesAndCounts.getCount();
    if (count > JSwordPassageService.MAX_VERSES_RETRIEVED) {
        throw new TranslatedException("subject_reference_search_too_big", Integer.valueOf(count).toString(), Integer.valueOf(JSwordPassageService.MAX_VERSES_RETRIEVED).toString());
    }
    return searchByReference(allReferencesAndCounts.getValue());
}
Also used : StringAndCount(com.tyndalehouse.step.core.models.StringAndCount) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException)

Example 9 with TranslatedException

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

the class SearchServiceImpl method retrieveStrongDefinitions.

/**
 * Retrieves the correct entity documents from a built up query and passed in parser
 *
 * @param sq              the search query
 * @param filteredStrongs the list of filtered strongs so far
 * @param p               the parser
 * @param query           the query
 * @param fullQuery       the full query so far
 * @return the list of matched entity documents
 */
private EntityDoc[] retrieveStrongDefinitions(final SearchQuery sq, final Set<String> filteredStrongs, final QueryParser p, final String query, final StringBuilder fullQuery) {
    if (StringUtils.isNotBlank(query)) {
        Query q;
        try {
            q = p.parse(query);
        } catch (final ParseException e) {
            throw new TranslatedException(e, "search_invalid");
        }
        final EntityDoc[] results = this.definitions.search(q);
        for (final EntityDoc doc : results) {
            // remove from matched strong if not in filter
            final String strongNumber = doc.get(STRONG_NUMBER_FIELD);
            if (isInFilter(strongNumber, sq)) {
                filteredStrongs.add(strongNumber);
                fullQuery.append(STRONG_QUERY);
                fullQuery.append(strongNumber);
                fullQuery.append(' ');
            }
        }
        return results;
    }
    return new EntityDoc[0];
}
Also used : Query(org.apache.lucene.search.Query) SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ParseException(org.apache.lucene.queryParser.ParseException)

Example 10 with TranslatedException

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

the class SearchServiceImpl method runTextSearch.

/**
 * Runs a text search, collapsing the restrictions if need be
 *
 * @param sq the search query contained
 * @return the search to be run
 */
private SearchResult runTextSearch(final SearchQuery sq) {
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    final String secondaryRange = currentSearch.getSecondaryRange();
    if (StringUtils.isBlank(secondaryRange)) {
        return runJSwordTextSearch(sq);
    }
    final String[] versions = currentSearch.getVersions();
    final String masterVersion = versions[0];
    final Book bookFromVersion = this.versificationService.getBookFromVersion(masterVersion);
    Key k;
    try {
        k = bookFromVersion.getKey(secondaryRange);
    } catch (NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", secondaryRange, bookFromVersion.getInitials());
    }
    k = intersect(k, this.jswordSearch.searchKeys(sq));
    return this.getSearchResultFromKey(sq, k);
}
Also used : TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Book(org.crosswire.jsword.book.Book) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch)

Aggregations

TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)15 Book (org.crosswire.jsword.book.Book)8 Key (org.crosswire.jsword.passage.Key)6 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)6 BibleBook (org.crosswire.jsword.versification.BibleBook)5 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)4 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)4 ParseException (org.apache.lucene.queryParser.ParseException)4 Query (org.apache.lucene.search.Query)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 StringAndCount (com.tyndalehouse.step.core.models.StringAndCount)3 HashSet (java.util.HashSet)3 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)3 Versification (org.crosswire.jsword.versification.Versification)3 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 QueryParser (org.apache.lucene.queryParser.QueryParser)2 BookException (org.crosswire.jsword.book.BookException)2 Passage (org.crosswire.jsword.passage.Passage)2 DirectoryListingInstaller (com.tyndalehouse.step.core.data.DirectoryListingInstaller)1 ValidationException (com.tyndalehouse.step.core.exceptions.ValidationException)1