Search in sources :

Example 1 with ExpandableSubjectHeadingEntry

use of com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry 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 ExpandableSubjectHeadingEntry

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

the class SubjectSearchServiceImpl method getHeadingsSearchEntries.

/**
 * @param start   the start time
 * @param results the results that have been found
 * @return the list of results
 */
private SearchResult getHeadingsSearchEntries(final long start, final EntityDoc[] results) {
    final List<SearchEntry> headingMatches = new ArrayList<SearchEntry>(results.length);
    for (final EntityDoc d : results) {
        headingMatches.add(new ExpandableSubjectHeadingEntry(d.get("root"), d.get("fullHeader"), d.get("alternate")));
    }
    // sort the results
    Collections.sort(headingMatches, new Comparator<SearchEntry>() {

        @Override
        public int compare(final SearchEntry o1, final SearchEntry o2) {
            final ExpandableSubjectHeadingEntry e1 = (ExpandableSubjectHeadingEntry) o1;
            final ExpandableSubjectHeadingEntry e2 = (ExpandableSubjectHeadingEntry) o2;
            return compareSubjectEntries(e1, e2);
        }
    });
    final SearchResult sr = new SearchResult();
    sr.setTimeTookTotal(System.currentTimeMillis() - start);
    sr.setTimeTookToRetrieveScripture(0);
    sr.setResults(headingMatches);
    sr.setTotal(headingMatches.size());
    return sr;
}
Also used : ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) SubjectHeadingSearchEntry(com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) ExpandableSubjectHeadingEntry(com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)

Example 3 with ExpandableSubjectHeadingEntry

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

the class SubjectSearchServiceImpl method searchByReference.

@Override
public SearchResult searchByReference(final String referenceQuerySyntax) {
    final SearchResult sr = new SearchResult();
    sr.setQuery("sr=" + referenceQuerySyntax);
    // referenceQuerySyntax could be a full referenceQuerySyntax, or could be the start of a referenceQuerySyntax here
    final EntityDoc[] results = getDocsByExpandedReferences(referenceQuerySyntax);
    final List<SearchEntry> resultList = new ArrayList<SearchEntry>(results.length);
    for (final EntityDoc d : results) {
        final ExpandableSubjectHeadingEntry entry = new ExpandableSubjectHeadingEntry(d.get("root"), d.get("fullHeader"), d.get("alternate"));
        resultList.add(entry);
    }
    sr.setResults(resultList);
    sr.setTotal(resultList.size());
    return sr;
}
Also used : EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ArrayList(java.util.ArrayList) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) SubjectHeadingSearchEntry(com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) ExpandableSubjectHeadingEntry(com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)

Aggregations

ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)3 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)3 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)2 ArrayList (java.util.ArrayList)2 PassageStat (com.tyndalehouse.step.core.models.stats.PassageStat)1