Search in sources :

Example 6 with SearchQuery

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");
    }
}
Also used : QueryParser(org.apache.lucene.queryParser.QueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) Query(org.apache.lucene.search.Query) SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ParseException(org.apache.lucene.queryParser.ParseException) HashSet(java.util.HashSet)

Example 7 with SearchQuery

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);
}
Also used : SearchQuery(com.tyndalehouse.step.core.service.impl.SearchQuery) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) SubjectHeadingSearchEntry(com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry) VerseSearchEntry(com.tyndalehouse.step.core.models.search.VerseSearchEntry) TimelineEventSearchEntry(com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) Test(org.junit.Test)

Aggregations

SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)7 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 VerseSearchEntry (com.tyndalehouse.step.core.models.search.VerseSearchEntry)3 Test (org.junit.Test)3 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)2 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)2 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)2 IndividualSearch (com.tyndalehouse.step.core.service.impl.IndividualSearch)2 ParseException (org.apache.lucene.queryParser.ParseException)2 Query (org.apache.lucene.search.Query)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)1 TimelineEventSearchEntry (com.tyndalehouse.step.core.models.search.TimelineEventSearchEntry)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)1 QueryParser (org.apache.lucene.queryParser.QueryParser)1