Search in sources :

Example 16 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class EntityIndexReaderImpl method extractDocIds.

/**
 * Extracts the query results into an entity doc
 *
 * @param collector the collector with the results
 * @return all the entity documents
 */
private EntityDoc[] extractDocIds(final AllResultsCollector collector) {
    try {
        final List<Integer> docIds = collector.getDocIds();
        final EntityDoc[] docs = new EntityDoc[docIds.size()];
        for (int ii = 0; ii < docIds.size(); ii++) {
            docs[ii] = new EntityDoc(this.searcher.doc(docIds.get(ii)));
        }
        return docs;
    } catch (final IOException e) {
        throw new StepInternalException("Unable to extract results from query", e);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) IOException(java.io.IOException)

Example 17 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class EntityIndexReaderImpl method extractDocIds.

/**
 * Extracts all the results
 *
 * @param results the results that have been collected
 * @return the results
 */
private EntityDoc[] extractDocIds(final TopDocs results) {
    try {
        final ScoreDoc[] scoreDocs = results.scoreDocs;
        final EntityDoc[] docs = new EntityDoc[scoreDocs.length];
        for (int ii = 0; ii < scoreDocs.length; ii++) {
            docs[ii] = new EntityDoc(this.searcher.doc(scoreDocs[ii].doc));
        }
        return docs;
    } catch (final IOException e) {
        throw new StepInternalException("Unable to extract results", e);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) IOException(java.io.IOException)

Example 18 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class EntityIndexReaderImpl method search.

@Override
public EntityDoc[] search(final Query query, final int max, final Sort sortField, final Filter filter) {
    LOGGER.debug("Search query is [{}]", query);
    try {
        final TopDocs search;
        if (sortField != null) {
            search = this.searcher.search(query, filter, max, sortField);
        } else {
            search = this.searcher.search(query, filter, max);
        }
        final EntityDoc[] results = new EntityDoc[search.scoreDocs.length];
        for (int ii = 0; ii < search.scoreDocs.length; ii++) {
            results[ii] = new EntityDoc(this.searcher.doc(search.scoreDocs[ii].doc));
        }
        return results;
    } catch (final IOException e) {
        throw new StepInternalException("Failed to search", e);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) IOException(java.io.IOException)

Example 19 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc 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 20 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc 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

EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)39 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)5 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)5 LexiconSuggestion (com.tyndalehouse.step.core.models.LexiconSuggestion)5 ParseException (org.apache.lucene.queryParser.ParseException)5 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)4 IOException (java.io.IOException)4 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)4 Query (org.apache.lucene.search.Query)4 BookAndBibleCount (com.tyndalehouse.step.core.models.search.BookAndBibleCount)3 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)3 QueryParser (org.apache.lucene.queryParser.QueryParser)3 Key (org.crosswire.jsword.passage.Key)3 ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)2 LexicalSearchEntry (com.tyndalehouse.step.core.models.search.LexicalSearchEntry)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)2