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;
}
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());
}
}
}
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());
}
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];
}
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);
}
Aggregations