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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations