Search in sources :

Example 11 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class SearchServiceImpl method adaptQueryForRelatedStrongSearch.

/**
 * Adapts the search query to be used in a strong search
 *
 * @param sq the search query object
 * @return a list of strong numbers
 */
private Set<String> adaptQueryForRelatedStrongSearch(final SearchQuery sq) {
    final Set<String> strongsFromQuery = getStrongsFromTextCriteria(sq);
    // look up the related strong numbers
    final Set<String> filteredStrongs = new HashSet<>(strongsFromQuery.size());
    final StringBuilder fullQuery = new StringBuilder(64);
    final QueryParser p = new QueryParser(Version.LUCENE_30, STRONG_NUMBER_FIELD, this.definitions.getAnalyzer());
    // get all words suggested in query
    final String query = retrieveStrongs(strongsFromQuery);
    final EntityDoc[] results = retrieveStrongDefinitions(sq, filteredStrongs, p, query, fullQuery);
    // now get all related words:
    final String relatedQuery = getRelatedStrongQuery(results);
    final EntityDoc[] relatedResults = retrieveStrongDefinitions(sq, filteredStrongs, p, relatedQuery, fullQuery);
    setUniqueConsideredDefinitions(sq, results, relatedResults);
    // append range to query
    sq.getCurrentSearch().setQuery(fullQuery.toString().toLowerCase(), true);
    return filteredStrongs;
}
Also used : QueryParser(org.apache.lucene.queryParser.QueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) HashSet(java.util.HashSet)

Example 12 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class SearchServiceImpl method setDefinitionForResults.

/**
 * Sets the definitions onto the result object
 *
 * @param result             the result object
 * @param lexiconDefinitions the definitions that have been included in the search
 */
private void setDefinitionForResults(final SearchResult result, final List<EntityDoc> lexiconDefinitions, SuggestionType suggestionType) {
    Collections.sort(lexiconDefinitions, new GlossComparator());
    List<LexiconSuggestion> suggestions = new ArrayList(lexiconDefinitions.size());
    for (final EntityDoc def : lexiconDefinitions) {
        suggestions.add(convertToSuggestion(def, null));
    }
    result.setDefinitions(suggestions);
}
Also used : ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) GlossComparator(com.tyndalehouse.step.core.service.helpers.GlossComparator)

Example 13 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class SearchServiceImpl method searchTextFieldsForDefinition.

/**
 * Searches the underlying DB for the relevant entry
 *
 * @param searchQuery the query that is being passed in
 * @return the list of strongs matched
 */
private Set<String> searchTextFieldsForDefinition(final String searchQuery) {
    // first look through the text forms
    final EntityDoc[] results = this.specificForms.search(new String[] { "accentedUnicode" }, searchQuery, null, null, false);
    if (results.length == 0) {
        return lookupFromLexicon(searchQuery);
    }
    // if we matched more than one, then we don't have our assumed uniqueness... log warning and
    // continue with first matched strong
    final Set<String> listOfStrongs = new HashSet<String>();
    for (final EntityDoc f : results) {
        listOfStrongs.add(f.get(STRONG_NUMBER_FIELD));
    }
    return listOfStrongs;
}
Also used : EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) HashSet(java.util.HashSet)

Example 14 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class SearchServiceImpl method lookupFromLexicon.

/**
 * Looks up the search criteria from the lexicon
 *
 * @param query the query
 * @return a list of strong numbers
 */
private Set<String> lookupFromLexicon(final String query) {
    // if we still have nothing, then look through the definitions
    final QueryParser parser = new QueryParser(Version.LUCENE_30, "accentedUnicode", this.definitions.getAnalyzer());
    Query parsed;
    try {
        parsed = parser.parse(QueryParser.escape(query));
    } catch (final ParseException e) {
        throw new TranslatedException(e, "search_invalid");
    }
    final EntityDoc[] results = this.definitions.search(parsed);
    final Set<String> matchedStrongs = new HashSet<String>();
    for (final EntityDoc d : results) {
        matchedStrongs.add(d.get(STRONG_NUMBER_FIELD));
    }
    return matchedStrongs;
}
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 15 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class LoaderTest method testRobinsonMorphology.

/**
 * tests loading of robinson's morphology codes
 */
@Test
public void testRobinsonMorphology() {
    getLoader("test.data.path.morphology.robinson", "robinson_morphology.csv").loadRobinsonMorphology();
    // check verb columns
    EntityDoc[] entities = getEntities(1, "morphology", "code", "V-2AAP-DSM");
    EntityDoc e = entities[0];
    assertEquals("Verb", e.get("function"));
    assertEquals("2nd Aorist", e.get("tense"));
    assertEquals("Active", e.get("voice"));
    assertEquals("Participle", e.get("mood"));
    assertEquals("Dative", e.get("case"));
    assertEquals("Singular", e.get("number"));
    assertEquals("Masculine", e.get("gender"));
    // check person and function
    entities = getEntities(1, "morphology", "code", "F-1ASM");
    e = entities[0];
    assertEquals("1st", e.get("person"));
    assertEquals("Reflexive pronoun", e.get("function"));
    // check person and function
    entities = getEntities(1, "morphology", "code", "F-1ASM");
    e = entities[0];
    assertEquals("1st", e.get("person"));
    assertEquals("Reflexive pronoun", e.get("function"));
    entities = getEntities(1, "morphology", "code", "D-NPM-C");
    e = entities[0];
    assertEquals("Contracted", e.get("suffix"));
}
Also used : EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) Test(org.junit.Test)

Aggregations

EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)39 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)5 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)5 LexiconSuggestion (com.tyndalehouse.step.core.models.LexiconSuggestion)5 ParseException (org.apache.lucene.queryParser.ParseException)5 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)4 IOException (java.io.IOException)4 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)4 Query (org.apache.lucene.search.Query)4 BookAndBibleCount (com.tyndalehouse.step.core.models.search.BookAndBibleCount)3 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)3 QueryParser (org.apache.lucene.queryParser.QueryParser)3 Key (org.crosswire.jsword.passage.Key)3 ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)2 LexicalSearchEntry (com.tyndalehouse.step.core.models.search.LexicalSearchEntry)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)2