Search in sources :

Example 1 with SearchQuery

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);
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) ArrayList(java.util.ArrayList)

Example 2 with SearchQuery

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());
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) VerseSearchEntry(com.tyndalehouse.step.core.models.search.VerseSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) Test(org.junit.Test)

Example 3 with SearchQuery

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());
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) VerseSearchEntry(com.tyndalehouse.step.core.models.search.VerseSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) Test(org.junit.Test)

Example 4 with SearchQuery

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);
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) IndividualSearch(com.tyndalehouse.step.core.service.impl.IndividualSearch) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Example 5 with SearchQuery

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];
}
Also used : Query(org.apache.lucene.search.Query) SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ParseException(org.apache.lucene.queryParser.ParseException)

Aggregations

SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)7 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 VerseSearchEntry (com.tyndalehouse.step.core.models.search.VerseSearchEntry)3 Test (org.junit.Test)3 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)2 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)2 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)2 IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)2 ParseException (org.apache.lucene.queryParser.ParseException)2 Query (org.apache.lucene.search.Query)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)1 TimelineEventSearchEntry (com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)1 QueryParser (org.apache.lucene.queryParser.QueryParser)1