Search in sources :

Example 1 with SearchResult

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

the class AnalysisServiceImpl method getSubjectStats.

/**
 * Subject stats.
 *
 * @param version   the version
 * @param reference the reference
 * @param scopeType
 * @return the passage stat
 */
private PassageStat getSubjectStats(final String version, final String reference, final ScopeType scopeType) {
    final SearchResult subjectResults = this.subjects.searchByReference(getReferenceSyntax(reference, version, scopeType));
    final PassageStat stat = new PassageStat();
    // we duplicate the set here because we'd like to keep the casing...
    final List<SearchEntry> results = subjectResults.getResults();
    for (final SearchEntry entry : results) {
        if (entry instanceof ExpandableSubjectHeadingEntry) {
            final ExpandableSubjectHeadingEntry subjectEntry = (ExpandableSubjectHeadingEntry) entry;
            // we will first do the subheading because ideally we want that 'case' to be the master case,
            // i.e. David rather than DAVID
            final String subjectHeading = subjectEntry.getHeading();
            if (subjectHeading != null && !stopSubjects.contains(subjectHeading.toUpperCase())) {
                stat.addWordTryCases(CLEAN_UP_DIGITS.matcher(subjectHeading).replaceAll(""));
            }
            final String root = subjectEntry.getRoot();
            if (root != null && !stopSubjects.contains(root.toUpperCase())) {
                stat.addWordTryCases(CLEAN_UP_DIGITS.matcher(root).replaceAll(root));
            }
        }
    }
    return stat;
}
Also used : PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) ExpandableSubjectHeadingEntry(com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)

Example 2 with SearchResult

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

the class SearchServiceImpl method buildTimelineSearchResults.

/**
 * Construct the relevant entity structure to represent timeline search results
 *
 * @param sq     the search query
 * @param events the list of events retrieved
 * @return the search results
 */
private SearchResult buildTimelineSearchResults(final SearchQuery sq, final EntityDoc[] events) {
    final List<SearchEntry> results = new ArrayList<SearchEntry>();
    final SearchResult r = new SearchResult();
    r.setResults(results);
    for (final EntityDoc e : events) {
        final String refs = e.get("storedReferences");
        final String[] references = StringUtils.split(refs);
        final List<VerseSearchEntry> verses = new ArrayList<VerseSearchEntry>();
        // TODO FIXME: REFACTOR to only make 1 jsword call?
        for (final String ref : references) {
            // TODO: REFACTOR only supports one version lookup
            final VerseSearchEntry verseEntry = new VerseSearchEntry();
            verses.add(verseEntry);
        }
        final TimelineEventSearchEntry entry = new TimelineEventSearchEntry();
        entry.setId(e.get("id"));
        entry.setDescription(e.get("name"));
        entry.setVerses(verses);
        results.add(entry);
    }
    return r;
}
Also used : TimelineEventSearchEntry(com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry) ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) VerseSearchEntry(com.tyndalehouse.step.core.models.search.VerseSearchEntry) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) KeyedSearchResultSearchEntry(com.tyndalehouse.step.core.models.search.KeyedSearchResultSearchEntry) TimelineEventSearchEntry(com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry) VerseSearchEntry(com.tyndalehouse.step.core.models.search.VerseSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) LexicalSearchEntry(com.tyndalehouse.step.core.models.search.LexicalSearchEntry)

Example 3 with SearchResult

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

the class SearchServiceImpl method runStrongTextSearch.

/**
 * Runs the search, and adds the strongs to the search results
 *
 * @param sq      the search criteria
 * @param strongs the list of strongs that were searched for
 * @return the search results
 */
private SearchResult runStrongTextSearch(final SearchQuery sq, final Set<String> strongs, final String options) {
    Key key = runStrongTextSearchKeys(sq, strongs);
    final SearchResult textResults = buildCombinedVerseBasedResults(sq, key, options);
    textResults.setStrongHighlights(new ArrayList<>(strongs));
    return textResults;
}
Also used : SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Example 4 with SearchResult

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

the class SearchServiceImpl method doSearch.

/**
 * Carries out the required search
 *
 * @param sq the sq
 * @return the search result
 */
private SearchResult doSearch(final SearchQuery sq, final String options) {
    final long start = System.currentTimeMillis();
    SearchResult result;
    // if we've only got one search, we want to retrieve the keys, the page, etc. all in one go
    try {
        if (sq.isIndividualSearch()) {
            result = executeOneSearch(sq, options);
        } else {
            result = executeJoiningSearches(sq);
        }
    } catch (final AbortQueryException ex) {
        result = new SearchResult();
    }
    // we split the query into separate searches
    // we run the search against the selected versions
    // we retrieve the keys
    // join the keys
    // return the results
    result.setSearchType(getBestSearchType(sq));
    result.setPageSize(sq.getPageSize());
    result.setPageNumber(sq.getPageNumber());
    result.setTimeTookTotal(System.currentTimeMillis() - start);
    result.setQuery(sq.getOriginalQuery());
    setBestRestriction(sq, result);
    final String[] allVersions = sq.getCurrentSearch().getVersions();
    result.setMasterVersion(this.versionResolver.getShortName(allVersions[0]));
    result.setExtraVersions(StringUtils.join(allVersions, 1));
    specialSort(sq, result);
    enrichWithLanguages(sq, result);
    return result;
}
Also used : SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) AbortQueryException(com.tyndalehouse.step.core.service.impl.AbortQueryException)

Example 5 with SearchResult

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

the class SubjectSearchServiceImpl method getResultsAsHeadings.

private SearchResult getResultsAsHeadings(SearchQuery sq, String[] searchableVersions, Key allTopics) {
    final SearchResult headingsSearch = this.jswordSearch.getResultsFromTrimmedKeys(sq, searchableVersions, allTopics.getCardinality(), allTopics, HEADINGS_ONLY);
    // build the results and then return
    final SubjectHeadingSearchEntry headings = new SubjectHeadingSearchEntry();
    headings.setHeadingsSearch(headingsSearch);
    // return the results
    final SearchResult sr = new SearchResult();
    sr.addEntry(headings);
    sr.setTotal(headingsSearch.getTotal());
    sr.setTimeTookToRetrieveScripture(headingsSearch.getTimeTookToRetrieveScripture());
    return sr;
}
Also used : SubjectHeadingSearchEntry(com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Aggregations

SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)16 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)5 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)4 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)3 ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)3 IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)3 ArrayList (java.util.ArrayList)3 TimelineEventSearchEntry (com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry)2 VerseSearchEntry (com.tyndalehouse.step.core.models.search.VerseSearchEntry)2 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)2 LookupOption (com.tyndalehouse.step.core.models.LookupOption)1 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)1 KeyedSearchResultSearchEntry (com.tyndalehouse.step.core.models.search.KeyedSearchResultSearchEntry)1 LexicalSearchEntry (com.tyndalehouse.step.core.models.search.LexicalSearchEntry)1 PassageStat (com.tyndalehouse.step.core.models.stats.PassageStat)1 AbortQueryException (com.tyndalehouse.step.core.service.impl.AbortQueryException)1 Key (org.crosswire.jsword.passage.Key)1 Passage (org.crosswire.jsword.passage.Passage)1 RangedPassage (org.crosswire.jsword.passage.RangedPassage)1 VerseKey (org.crosswire.jsword.passage.VerseKey)1