Search in sources :

Example 1 with AbortQueryException

use of com.tyndalehouse.step.core.service.impl.AbortQueryException in project step by STEPBible.

the class SearchServiceImpl method doSearch.

/**
 * Carries out the required search
 *
 * @param sq the sq
 * @return the search result
 */
private SearchResult doSearch(final SearchQuery sq, final String options) {
    final long start = System.currentTimeMillis();
    SearchResult result;
    // if we've only got one search, we want to retrieve the keys, the page, etc. all in one go
    try {
        if (sq.isIndividualSearch()) {
            result = executeOneSearch(sq, options);
        } else {
            result = executeJoiningSearches(sq);
        }
    } catch (final AbortQueryException ex) {
        result = new SearchResult();
    }
    // we split the query into separate searches
    // we run the search against the selected versions
    // we retrieve the keys
    // join the keys
    // return the results
    result.setSearchType(getBestSearchType(sq));
    result.setPageSize(sq.getPageSize());
    result.setPageNumber(sq.getPageNumber());
    result.setTimeTookTotal(System.currentTimeMillis() - start);
    result.setQuery(sq.getOriginalQuery());
    setBestRestriction(sq, result);
    final String[] allVersions = sq.getCurrentSearch().getVersions();
    result.setMasterVersion(this.versionResolver.getShortName(allVersions[0]));
    result.setExtraVersions(StringUtils.join(allVersions, 1));
    specialSort(sq, result);
    enrichWithLanguages(sq, result);
    return result;
}
Also used : SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) AbortQueryException(com.tyndalehouse.step.core.service.impl.AbortQueryException)

Example 2 with AbortQueryException

use of com.tyndalehouse.step.core.service.impl.AbortQueryException in project step by STEPBible.

the class SearchServiceImpl method findByTransliteration.

/**
 * Runs the transliteration rules on the input in an attempt to match an entry in the lexicon
 *
 * @param query   the query to be found
 * @param isGreek true to indicate Greek, false to indicate Hebrew
 * @return the strongs that have been found/matched.
 */
private Set<String> findByTransliteration(final String query, final boolean isGreek) {
    // first find by transliterations that we have
    final String lowerQuery = query.toLowerCase(Locale.ENGLISH);
    final String simplifiedTransliteration = OriginalWordSuggestionServiceImpl.getSimplifiedTransliterationClause(isGreek, lowerQuery, false);
    final EntityDoc[] specificFormEntities = this.specificForms.searchSingleColumn("simplifiedTransliteration", simplifiedTransliteration, getFilter(isGreek));
    // finally, if we haven't found anything, then abort
    if (specificFormEntities.length != 0) {
        final Set<String> strongs = new HashSet<String>(specificFormEntities.length);
        // nothing to search for..., so abort query
        for (final EntityDoc f : specificFormEntities) {
            strongs.add(f.get(STRONG_NUMBER_FIELD));
        }
        return strongs;
    }
    final MultiFieldQueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new String[] { "simplifiedTransliteration", "stepTransliteration", "otherTransliteration" }, this.definitions.getAnalyzer());
    try {
        final Query luceneQuery = queryParser.parse("-stopWord:true " + lowerQuery);
        final EntityDoc[] results = this.definitions.search(luceneQuery);
        if (results.length == 0) {
            throw new AbortQueryException("No definitions found for input");
        }
        final Set<String> strongs = new HashSet<String>(results.length);
        for (final EntityDoc d : results) {
            strongs.add(d.get(STRONG_NUMBER_FIELD));
        }
        return strongs;
    } catch (final ParseException e) {
        throw new TranslatedException(e, "search_invalid");
    }
}
Also used : 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) AbortQueryException(com.tyndalehouse.step.core.service.impl.AbortQueryException)

Aggregations

AbortQueryException (com.tyndalehouse.step.core.service.impl.AbortQueryException)2 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)1 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)1 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)1 HashSet (java.util.HashSet)1 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Query (org.apache.lucene.search.Query)1