use of com.tyndalehouse.step.core.service.impl.SearchQuery 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.SearchQuery in project step by STEPBible.
the class JSwordSearchServiceImplTest method testMorphology.
/**
* Random tests
*/
@Test
public void testMorphology() {
final List<SearchEntry> results = this.search.search(new SearchQuery("+[Mat-Rev] +morph:G2570*A-NSM*", new String[] { "KJV" }, "true", 0, 1, 1000000, null), "ESV_th").getResults();
for (SearchEntry result : results) {
LOGGER.info(((VerseSearchEntry) result).getKey());
}
assertFalse(results.isEmpty());
}
use of com.tyndalehouse.step.core.service.impl.SearchQuery in project step by STEPBible.
the class JSwordSearchServiceImplTest method testGood.
/**
* Random tests
*/
@Test
public void testGood() {
final List<SearchEntry> results = this.search.search(new SearchQuery("+[Mat-Rev] good~", new String[] { "ESV_th" }, "true", 0, 1, 1000000, null), "ESV_th").getResults();
for (SearchEntry result : results) {
LOGGER.trace(((VerseSearchEntry) result).getKey());
}
assertFalse(results.isEmpty());
}
use of com.tyndalehouse.step.core.service.impl.SearchQuery 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);
}
use of com.tyndalehouse.step.core.service.impl.SearchQuery 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];
}
Aggregations