use of com.tyndalehouse.step.core.service.impl.SearchQuery 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");
}
}
use of com.tyndalehouse.step.core.service.impl.SearchQuery in project step by STEPBible.
the class SearchServiceImplTest method testSubjectSearch.
/**
* test exact strong match
*/
@Test
public void testSubjectSearch() {
final SearchResult searchSubject = this.searchServiceUnderTest.search(new SearchQuery("sh=elijah", new String[] { "ESV_th" }, "false", 0, 1, 1, null));
final List<SearchEntry> entries = ((SubjectHeadingSearchEntry) searchSubject.getResults().get(0)).getHeadingsSearch().getResults();
for (final SearchEntry e : entries) {
LOGGER.debug(((VerseSearchEntry) e).getPreview());
}
assertTrue(searchSubject.getResults().size() > 0);
}
Aggregations