use of com.tyndalehouse.step.core.models.search.SyntaxSuggestion in project step by STEPBible.
the class SearchServiceImpl method enhanceSearchTokens.
/**
* Enhances search tokens, meaning that <p /> for versions, we return the short initials and long initials in the
* form of a 'BibleVersion' <p /> for references, we return the keywraper <p /> for strong numbers, we return the
* lexicon suggestion <p /> for everything else, null.
*
* @param masterVersion the master version to use looking up references and so on.
* @param searchTokens a list of search tokens
* @return with enhanced meta data if any
*/
private void enhanceSearchTokens(final String masterVersion, final List<SearchToken> searchTokens) {
for (SearchToken st : searchTokens) {
final String tokenType = st.getTokenType();
if (SearchToken.VERSION.equals(tokenType)) {
// probably need to show the short initials
BibleVersion version = new BibleVersion();
version.setInitials(this.versionResolver.getLongName(st.getToken()));
version.setShortInitials(this.versionResolver.getShortName(st.getToken()));
st.setEnhancedTokenInfo(version);
} else if (SearchToken.REFERENCE.equals(tokenType)) {
// could take the key but that has all parts combined
final KeyWrapper kw = this.bibleInfoService.getKeyInfo(st.getToken(), masterVersion, masterVersion);
String osisRef;
if (kw.getKey() != null) {
osisRef = kw.getKey().getOsisRef();
} else {
osisRef = kw.getOsisKeyId();
}
final BookName bookName = new BookName(kw.getName(), kw.getName(), BookName.Section.PASSAGE, false, osisRef);
st.setEnhancedTokenInfo(bookName);
} else if (SearchToken.STRONG_NUMBER.equals(tokenType)) {
// hit the index and look up that strong number...
st.setEnhancedTokenInfo(this.lexiconDefinitionService.lookup(st.getToken()));
} else if (SearchToken.EXACT_FORM.equals(tokenType)) {
ExactForm ef = new ExactForm();
ef.setText(st.getToken());
ef.setGreek(GreekUtils.isGreekText(st.getToken()));
st.setEnhancedTokenInfo(ef);
} else if (SearchToken.SUBJECT_SEARCH.equals(tokenType) || SearchToken.NAVE_SEARCH.equals(tokenType) || SearchToken.NAVE_SEARCH_EXTENDED.equals(tokenType)) {
SubjectSuggestion ss = new SubjectSuggestion();
ss.setValue(st.getToken());
st.setEnhancedTokenInfo(ss);
} else if (SearchToken.TEXT_SEARCH.equals(tokenType)) {
final TextSuggestion textSuggestion = new TextSuggestion();
textSuggestion.setText(st.getToken());
st.setEnhancedTokenInfo(textSuggestion);
} else if (SearchToken.MEANINGS.equals(tokenType)) {
final LexiconSuggestion meaningSuggestion = new LexiconSuggestion();
meaningSuggestion.setGloss(st.getToken());
st.setEnhancedTokenInfo(meaningSuggestion);
} else if (SearchToken.SYNTAX.equals(tokenType)) {
SyntaxSuggestion ss = new SyntaxSuggestion();
// take the first word, after stripping off any reference, etc.
String syntax = st.getToken();
syntax = IndividualSearch.MAIN_RANGE.matcher(syntax).replaceAll("").replaceAll("[()]+", "");
if (StringUtils.isBlank(syntax)) {
ss.setText("...");
} else {
int i = syntax.indexOf(' ');
if (i != -1) {
ss.setText(String.format(SYNTAX_FORMAT, syntax.substring(0, i + 1)));
} else {
ss.setText(String.format(SYNTAX_FORMAT, syntax));
}
}
ss.setValue(st.getToken());
st.setEnhancedTokenInfo(ss);
} else if (SearchToken.TOPIC_BY_REF.equals(st.getTokenType())) {
final TextSuggestion enhancedTokenInfo = new TextSuggestion();
enhancedTokenInfo.setText(st.getToken());
st.setEnhancedTokenInfo(enhancedTokenInfo);
} else if (SearchToken.RELATED_VERSES.equals(st.getTokenType())) {
final TextSuggestion enhancedTokenInfo = new TextSuggestion();
enhancedTokenInfo.setText(st.getToken());
st.setEnhancedTokenInfo(enhancedTokenInfo);
}
// nothing to do
// for subject searches or
// for text searches or
// for meaning searches
}
}
Aggregations