Search in sources :

Example 1 with DefaultSearchModifier

use of org.crosswire.jsword.index.search.DefaultSearchModifier in project step by STEPBible.

the class JSwordSearchServiceImpl method searchKeys.

@Override
public Key searchKeys(final SearchQuery sq) {
    final DefaultSearchModifier modifier = new DefaultSearchModifier();
    // we have a linked hashmap, because we want to preserve the order of the versions we're looking up
    // this was we end up with the results in the correct versification
    final Map<String, Key> resultsPerVersion = new LinkedHashMap<String, Key>();
    modifier.setRanked(sq.isRanked());
    // need to set to something sensible, other we may experience a
    // "Requested array size exceeds VM limit"
    modifier.setMaxResults(MAX_RESULTS);
    final IndividualSearch currentSearch = sq.getCurrentSearch();
    final boolean searchOnTaggedText = currentSearch.getType().isOriginalSearch();
    boolean searchExecuted = false;
    for (final String version : currentSearch.getVersions()) {
        // now for each version, we do the search and store it in a map
        final Book bible = this.av11nService.getBookFromVersion(version);
        // TODO: improvement investigate which is faster
        if (searchOnTaggedText) {
            // then we only do the search if the bible is tagged
            if (!this.metadataService.supportsStrongs(bible)) {
                continue;
            }
        }
        doSearch(modifier, resultsPerVersion, currentSearch, bible);
        searchExecuted = true;
    }
    if (searchOnTaggedText && !searchExecuted) {
        Book bible = this.av11nService.getBookFromVersion(JSwordPassageService.REFERENCE_BOOK);
        doSearch(modifier, resultsPerVersion, currentSearch, bible);
    }
    // no need to rank, since it won't be possible to rank accurately across versions
    return mergeSearches(resultsPerVersion);
}
Also used : Book(org.crosswire.jsword.book.Book) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) DefaultSearchModifier(org.crosswire.jsword.index.search.DefaultSearchModifier)

Aggregations

IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)1 Book (org.crosswire.jsword.book.Book)1 DefaultSearchModifier (org.crosswire.jsword.index.search.DefaultSearchModifier)1