Search in sources :

Example 1 with SubmissionImpl

use of gov.nih.nci.ctd2.dashboard.impl.SubmissionImpl in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method searchSingleTerm.

private void searchSingleTerm(final String singleTerm, final Map<Subject, Integer> subjects, final Map<Submission, Integer> submissions) {
    FullTextSession fullTextSession = Search.getFullTextSession(getSession());
    MultiFieldQueryParser multiFieldQueryParser = new MultiFieldQueryParser(defaultSearchFields, new KeywordAnalyzer());
    Query luceneQuery = null;
    try {
        luceneQuery = multiFieldQueryParser.parse(singleTerm);
        log.debug(luceneQuery);
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, searchableClasses);
    fullTextQuery.setReadOnly(true);
    List<?> list = fullTextQuery.list();
    fullTextSession.close();
    Integer numberOfSearchResults = getMaxNumberOfSearchResults();
    if (numberOfSearchResults > 0 && list.size() > numberOfSearchResults) {
        // if lte 0, the maximum number is ignored
        log.warn("search result number " + list.size() + " is larger than the maximum expected, " + numberOfSearchResults);
    }
    for (Object o : list) {
        if (o instanceof ObservationTemplate) {
            List<Submission> submissionList = queryWithClass("select o from SubmissionImpl as o where o.observationTemplate = :ot", "ot", (ObservationTemplate) o);
            for (Submission submission : submissionList) {
                if (submissions.containsKey(submission)) {
                    submissions.put(submission, submissions.get(submission) + 1);
                } else {
                    submissions.put(submission, 1);
                }
            }
        } else if (o instanceof Subject) {
            Subject s = (Subject) o;
            if (subjects.containsKey(s)) {
                subjects.put(s, subjects.get(s) + 1);
            } else {
                subjects.put(s, 1);
            }
        } else {
            log.warn("unexpected type returned by searching: " + o.getClass().getName());
        }
    }
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) FullTextSession(org.hibernate.search.FullTextSession) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Query(org.apache.lucene.search.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FullTextQuery(org.hibernate.search.FullTextQuery) TypedQuery(javax.persistence.TypedQuery) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) BigInteger(java.math.BigInteger) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextQuery(org.hibernate.search.FullTextQuery)

Aggregations

ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)1 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)1 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)1 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)1 BigInteger (java.math.BigInteger)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)1 MultiFieldQueryParser (org.apache.lucene.queryparser.classic.MultiFieldQueryParser)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Query (org.apache.lucene.search.Query)1 FullTextQuery (org.hibernate.search.FullTextQuery)1 FullTextSession (org.hibernate.search.FullTextSession)1