use of com.tyndalehouse.step.core.service.impl.IndividualSearch 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);
}
use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.
the class SearchServiceImpl method runJSwordTextSearch.
/**
* Runs a query against the JSword modules backends
*
* @param sq the search query contained
* @return the search to be run
*/
private SearchResult runJSwordTextSearch(SearchQuery sq) {
final IndividualSearch is = sq.getCurrentSearch();
// for text searches, we may have a prefix of t=
final String[] versions = is.getVersions();
if (versions.length == 1) {
return this.jswordSearch.search(sq, versions[0]);
}
// Options from user was not passed to this method
return buildCombinedVerseBasedResults(sq, this.jswordSearch.searchKeys(sq), "");
}
use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.
the class SearchServiceImpl method getKeysFromOriginalText.
/**
* Searches for all passage references matching an original text (greek or hebrew)
*
* @param sq the search criteria
* @return the list of verses
*/
private Key getKeysFromOriginalText(final SearchQuery sq) {
final IndividualSearch currentSearch = sq.getCurrentSearch();
final String[] soughtAfterVersions = currentSearch.getVersions();
// overwrite version with WHNU to do the search
if (GreekUtils.isGreekText(sq.getCurrentSearch().getQuery())) {
currentSearch.setVersions(BASE_GREEK_VERSIONS);
currentSearch.setQuery(unaccent(currentSearch.getQuery(), sq), true);
} else {
currentSearch.setVersions(new String[] { BASE_HEBREW_VERSION });
currentSearch.setQuery(unaccent(currentSearch.getQuery(), sq), true);
}
final Key resultKeys = this.jswordSearch.searchKeys(sq);
// now overwrite again and do the intersection with the normal text
currentSearch.setVersions(soughtAfterVersions);
return resultKeys;
}
use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.
the class SearchServiceImpl method runCorrectSearch.
/**
* Establishes what the correct search should be and kicks off the right type of search
*
* @param versions the list of versions
* @param references the list of references
* @param options the options
* @param displayMode the display mode
* @param filter the filter to apply to the searhc. Blank retrieves just the current search term, non-blank
* returns all non-blank (usually strong) matches as well
* @param sort the sort to apply to the search
* @param pageNumber the page number of interest
* @param context amount of context to be used in searhc
* @return the results
*/
private AbstractComplexSearch runCorrectSearch(final List<String> versions, final String references, final String options, final String displayMode, final List<SearchToken> searchTokens, final int pageNumber, final String filter, final String sort, final int context, final String userLanguage) {
final List<IndividualSearch> individualSearches = new ArrayList<IndividualSearch>(2);
String[] filters = null;
if (StringUtils.isNotBlank(filter)) {
filters = StringUtils.split(filter, "[ ,]+");
}
for (SearchToken st : searchTokens) {
final String tokenType = st.getTokenType();
if (SearchToken.STRONG_NUMBER.equals(tokenType)) {
addWordSearches(versions, references, st.getToken(), filters, individualSearches);
} else if (SearchToken.MEANINGS.equals(tokenType)) {
addSearch(SearchType.ORIGINAL_MEANING, versions, references, st.getToken(), filters, individualSearches);
} else if (SearchToken.EXACT_FORM.equals(tokenType)) {
addSearch(SearchType.EXACT_FORM, versions, references, st.getToken(), filters, individualSearches);
} else if (SearchToken.TEXT_SEARCH.equals(tokenType)) {
addSearch(SearchType.TEXT, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.SUBJECT_SEARCH.equals(tokenType)) {
addSearch(SearchType.SUBJECT_SIMPLE, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.NAVE_SEARCH.equals(tokenType)) {
addSearch(SearchType.SUBJECT_EXTENDED, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.NAVE_SEARCH_EXTENDED.equals(tokenType)) {
addSearch(SearchType.SUBJECT_FULL, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.TOPIC_BY_REF.equals(tokenType)) {
addSearch(SearchType.SUBJECT_RELATED, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.RELATED_VERSES.equals(tokenType)) {
addSearch(SearchType.RELATED_VERSES, versions, references, st.getToken(), null, individualSearches);
} else if (SearchToken.SYNTAX.equals(tokenType)) {
// add a number of searches from the query syntax given...
final IndividualSearch[] searches = new SearchQuery(st.getToken(), versions.toArray(new String[versions.size()]), null, context, pageNumber, references).getSearches();
for (IndividualSearch is : searches) {
individualSearches.add(is);
}
} else {
// ignore and do nothing - generally references and versions which have been parsed already
}
}
// we will prefer a word search to anything else...
if (individualSearches.size() != 0) {
return this.search(new SearchQuery(pageNumber, context, displayMode, sort, individualSearches.toArray(new IndividualSearch[individualSearches.size()])), options);
}
return this.bibleInfoService.getPassageText(versions.get(0), references, options, getExtraVersions(versions), displayMode, userLanguage);
}
use of com.tyndalehouse.step.core.service.impl.IndividualSearch in project step by STEPBible.
the class SearchServiceImpl method addWordSearches.
/**
* Adds a word search to the list of searches we will perform
*
* @param versions the list of versions
* @param references the list of references
* @param strong the strong number/criteria
* @param individualSearches the searches to perform
*/
private void addWordSearches(final List<String> versions, final String references, String strong, final String[] filters, final List<IndividualSearch> individualSearches) {
String[] filtersForSearch = filters;
if (filters == null || filters.length == 0) {
filtersForSearch = new String[] { strong };
} else if (filters.length == 1 && NO_FILTER.equals(filters[0])) {
filtersForSearch = new String[0];
}
boolean isGreek = strong.charAt(0) == 'G';
individualSearches.add(new IndividualSearch(isGreek ? SearchType.ORIGINAL_GREEK_RELATED : SearchType.ORIGINAL_HEBREW_RELATED, versions, strong, getInclusion(references), filtersForSearch));
}
Aggregations