Search in sources :

Example 11 with IndividualSearch

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

the class SearchServiceImpl method runStrongTextSearchKeys.

private Key runStrongTextSearchKeys(SearchQuery sq, Set<String> strongs) {
    // searches for strongs have got slightly more complicated now that we are doing augmented strongs as well...
    // so for example, we have the query strong:h00001 strong:h00002 strong:h00003 strong:h00004a strong:h00005a
    // we can run a simple strong search for normal strong numbers
    // unfortunately, we to need run an extra search for each of the augmented strong numbers
    // split the search into the standard search and the other searches
    final List<String> augmentedStrongs = new ArrayList<>(2);
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    String currentQuery = currentSearch.getQuery();
    final Matcher matchAugmentedStrongs = AUGMENTED_STRONG.matcher(currentQuery);
    final String simpleStrongSearch = matchAugmentedStrongs.replaceAll("");
    matchAugmentedStrongs.reset();
    while (matchAugmentedStrongs.find()) {
        final String as = matchAugmentedStrongs.group(1);
        augmentedStrongs.add(as);
        strongs.add(this.strongAugmentationService.reduce(as).toUpperCase());
    }
    // run the normal search
    Key key = null;
    if (simpleStrongSearch.contains("strong")) {
        currentSearch.setQuery(simpleStrongSearch);
        key = this.jswordSearch.searchKeys(sq);
    }
    // work out the original query without the normal strong numbers
    String blankQuery = ALL_STRONGS.matcher(currentQuery).replaceAll("");
    for (String as : augmentedStrongs) {
        currentSearch.setQuery(blankQuery + " strong:" + as.substring(0, as.length() - 1));
        Key potentialAugmentedResults = this.jswordSearch.searchKeys(sq);
        // filter results by augmented strong data set
        Key masterAugmentedFilter = this.strongAugmentationService.getVersesForAugmentedStrong(as);
        potentialAugmentedResults = intersect(potentialAugmentedResults, masterAugmentedFilter);
        // add results to current set
        if (key == null) {
            key = potentialAugmentedResults;
        } else {
            key.addAll(potentialAugmentedResults);
        }
    }
    currentSearch.setQuery(currentQuery);
    return key;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch)

Example 12 with IndividualSearch

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

the class SearchServiceImpl method enrichWithLanguages.

/**
 * Puts the languages of each module into the result returned to the UI.
 *
 * @param sq     the search query
 * @param result the result
 */
private void enrichWithLanguages(final SearchQuery sq, final SearchResult result) {
    IndividualSearch lastSearch = sq.getCurrentSearch();
    result.setLanguageCode(jswordMetadata.getLanguages(lastSearch.getVersions()));
}
Also used : IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch)

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