Search in sources :

Example 1 with TextSuggestion

use of com.tyndalehouse.step.core.models.search.TextSuggestion in project step by STEPBible.

the class TextSuggestionServiceImpl method collectNonExactMatches.

@Override
public TextSuggestion[] collectNonExactMatches(final TermsAndMaxCount<TextSuggestion> collector, final SuggestionContext context, final TextSuggestion[] alreadyRetrieved, final int leftToCollect) {
    final String input = context.getInput();
    if (INVALID_TEXT.matcher(input).find()) {
        return new TextSuggestion[0];
    }
    final TextSuggestion textSuggestion = new TextSuggestion();
    textSuggestion.setText(input);
    collector.setTotalCount(0);
    return new TextSuggestion[] { textSuggestion };
}
Also used : TextSuggestion(com.tyndalehouse.step.core.models.search.TextSuggestion)

Example 2 with TextSuggestion

use of com.tyndalehouse.step.core.models.search.TextSuggestion 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
    }
}
Also used : TextSuggestion(com.tyndalehouse.step.core.models.search.TextSuggestion) SyntaxSuggestion(com.tyndalehouse.step.core.models.search.SyntaxSuggestion) SubjectSuggestion(com.tyndalehouse.step.core.models.search.SubjectSuggestion)

Aggregations

TextSuggestion (com.tyndalehouse.step.core.models.search.TextSuggestion)2 SubjectSuggestion (com.tyndalehouse.step.core.models.search.SubjectSuggestion)1 SyntaxSuggestion (com.tyndalehouse.step.core.models.search.SyntaxSuggestion)1