Search in sources :

Example 6 with IndividualSearch

use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.

the class SearchServiceImpl method getStrongsFromCurrentSearch.

/**
 * splits up the query syntax and returns a list of all strong numbers required
 *
 * @param sq the search query
 * @return the list of strongs
 */
private Set<String> getStrongsFromCurrentSearch(final SearchQuery sq) {
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    final String searchStrong = currentSearch.getQuery();
    LOGGER.debug("Searching for strongs [{}]", searchStrong);
    return splitToStrongs(searchStrong, sq.getCurrentSearch().getType());
}
Also used : IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch)

Example 7 with IndividualSearch

use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.

the class SubjectSearchServiceImpl method search.

@Override
public SearchResult search(final SearchQuery sq) {
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    LOGGER.debug("Executing subject search of type [{}]", currentSearch.getType());
    SearchQuery currentQuery = sq;
    switch(currentSearch.getType()) {
        case SUBJECT_SIMPLE:
            final SearchResult simpleSearchResults = searchSimple(currentQuery);
            return simpleSearchResults;
        case SUBJECT_EXTENDED:
            final SearchResult searchResult = searchExtended(currentQuery);
            searchResult.setQuery(currentSearch.getQuery());
            return searchResult;
        case SUBJECT_FULL:
            return searchFull(currentQuery);
        case SUBJECT_RELATED:
            return relatedSubjects(currentQuery);
        default:
            break;
    }
    return searchSimple(currentQuery);
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Example 8 with IndividualSearch

use of com.tyndalehouse.step.core.service.impl.IndividualSearch 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 9 with IndividualSearch

use of com.tyndalehouse.step.core.service.impl.IndividualSearch 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)

Example 10 with IndividualSearch

use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.

the class SearchServiceImpl method buildCombinedVerseBasedResults.

/**
 * Builds the combined results
 *
 * @param sq      the search query object
 * @param results the set of keys that have been retrieved by each search
 * @return the set of results
 */
private SearchResult buildCombinedVerseBasedResults(final SearchQuery sq, final Key results, final String options) {
    // combine the results into 1 giant keyed map
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    Key adaptedResults = results;
    if (adaptedResults == null) {
        adaptedResults = PassageKeyFactory.instance().createEmptyKeyList(this.versificationService.getVersificationForVersion(JSwordPassageService.BEST_VERSIFICATION));
    }
    int total = adaptedResults.getCardinality();
    final Key pagedKeys = this.jswordSearch.rankAndTrimResults(sq, adaptedResults);
    // retrieve scripture content and set up basics
    final SearchResult resultsForKeys = this.jswordSearch.getResultsFromTrimmedKeys(sq, currentSearch.getVersions(), total, pagedKeys, options);
    resultsForKeys.setTotal(this.jswordSearch.getTotal(adaptedResults));
    resultsForKeys.setQuery(sq.getOriginalQuery());
    return resultsForKeys;
}
Also used : IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Aggregations

IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)12 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)3 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)2 ArrayList (java.util.ArrayList)2 Book (org.crosswire.jsword.book.Book)2 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 Matcher (java.util.regex.Matcher)1 DefaultSearchModifier (org.crosswire.jsword.index.search.DefaultSearchModifier)1 Key (org.crosswire.jsword.passage.Key)1 Passage (org.crosswire.jsword.passage.Passage)1 RangedPassage (org.crosswire.jsword.passage.RangedPassage)1 VerseKey (org.crosswire.jsword.passage.VerseKey)1