use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SubjectSearchServiceImpl method naveDocsToReference.
/**
* Converts a set of nave documents to their reference equivalent
*
* @param extendedDocs
* @return
*/
private Key naveDocsToReference(SearchQuery sq, EntityDoc[] extendedDocs) {
String mainVersion = sq.getCurrentSearch().getVersions()[0];
Book naveVersion = this.jSwordVersificationService.getBookFromVersion(JSwordPassageService.BEST_VERSIFICATION);
Book bookFromVersion = this.jSwordVersificationService.getBookFromVersion(mainVersion);
Key passageKey = null;
for (EntityDoc d : extendedDocs) {
String storedReferences = d.get(NAVE_STORED_REFERENCES);
final Key key;
try {
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
key = naveVersion.getKey(storedReferences);
} catch (Exception ex) {
throw new StepInternalException("Stored references are unparseable in nave module: " + storedReferences);
}
if (passageKey == null) {
passageKey = key;
} else {
passageKey.addAll(key);
}
}
return passageKey;
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SubjectEntryServiceImpl method getVersesForResults.
/**
* obtains the verses for all results
*
* @param results the results
* @param versions the version in which to look it up
* @param context the context to expand with the reference
* @return the verses
*/
private SubjectEntries getVersesForResults(final EntityDoc[] results, final String[] versions, final String limitingScopeReference, final int context) {
final List<OsisWrapper> verses = new ArrayList<OsisWrapper>(32);
boolean masterVersionSwapped = false;
for (final EntityDoc doc : results) {
final String references = doc.get("references");
masterVersionSwapped |= collectVersesFromReferences(verses, versions, references, limitingScopeReference, context);
}
return new SubjectEntries(verses, masterVersionSwapped);
}
use of com.tyndalehouse.step.core.data.EntityDoc 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];
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method setUniqueConsideredDefinitions.
/**
* Sets up all definitions that are related, regardless of whether they have been filtered out. Makes a unique set
* of these
*
* @param sq the search query that is being
* @param results the results from the direct strong search
* @param relatedResults the related results
*/
private void setUniqueConsideredDefinitions(final SearchQuery sq, final EntityDoc[] results, final EntityDoc[] relatedResults) {
// make entity docs unique:
final Set<EntityDoc> joinedDocs = new HashSet<EntityDoc>(relatedResults.length + results.length);
final Set<String> strongNumbers = new HashSet<String>(relatedResults.length + results.length);
for (final EntityDoc queryDoc : results) {
final String strong = queryDoc.get(STRONG_NUMBER_FIELD);
if (!strongNumbers.contains(strong)) {
joinedDocs.add(queryDoc);
strongNumbers.add(strong);
}
}
for (final EntityDoc relatedDoc : relatedResults) {
final String strong = relatedDoc.get(STRONG_NUMBER_FIELD);
if (!strongNumbers.contains(strong)) {
joinedDocs.add(relatedDoc);
strongNumbers.add(strong);
}
}
sq.setDefinitions(new ArrayList<EntityDoc>(joinedDocs));
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method adaptQueryForMeaningSearch.
/**
* Looks up all the glosses for a particular word, and then adapts to strong search and continues as before
*
* @param sq search criteria
* @return a list of matching strongs
*/
private Set<String> adaptQueryForMeaningSearch(final SearchQuery sq) {
final String query = sq.getCurrentSearch().getQuery();
final QueryParser queryParser = new QueryParser(Version.LUCENE_30, "translationsStem", this.definitions.getAnalyzer());
queryParser.setDefaultOperator(Operator.OR);
try {
// we need to also add the step gloss, but since we need the analyser for stems,
// we want to use the query parser that does the tokenization for us
// could probably do better if required
String[] terms = StringUtils.split(query);
StringBuilder finalQuery = new StringBuilder();
for (String term : terms) {
final String escapedTerm = QueryParser.escape(term);
finalQuery.append(escapedTerm);
finalQuery.append(" stepGlossStem:");
finalQuery.append(escapedTerm);
}
final Query parsed = queryParser.parse("-stopWord:true " + finalQuery.toString());
final EntityDoc[] matchingMeanings = this.definitions.search(parsed);
final Set<String> strongs = new HashSet<String>(matchingMeanings.length);
for (final EntityDoc d : matchingMeanings) {
final String strongNumber = d.get(STRONG_NUMBER_FIELD);
if (isInFilter(strongNumber, sq)) {
strongs.add(strongNumber);
}
}
final String textQuery = getQuerySyntaxForStrongs(strongs, sq);
sq.getCurrentSearch().setQuery(textQuery, true);
sq.setDefinitions(matchingMeanings);
// return the strongs that the search will match
return strongs;
} catch (final ParseException e) {
throw new TranslatedException(e, "search_invalid");
}
}
Aggregations