示例#1
0
 def subject(self, form):
     if not form:
         # Simply return the search form
         return [self._render_template('subject.html')]
     self._log(10, 'subject')
     session = self.session
     db = self.database
     queryFactory = self.queryFactory
     maximumRecords = int(form.getvalue('maximumRecords', 20))
     startRecord = int(form.getvalue('startRecord', 1))
     qString = form.getvalue('query')
     if not qString:
         qString = generate_cqlQuery(form)
         if not (len(qString)):
             self._log(40, 'Unable to generate CQL subject finder query')
             return self._render_template('fail/invalidSubjectQuery.html')
     try:
         query = queryFactory.get_query(session, qString, format='cql')
     except CQLDiagnostic:
         return self._render_template('fail/invalidSubjectQuery.html')
     session.database = 'db_ead_cluster'
     clusDb = session.server.get_object(session, session.database)
     rs = clusDb.search(session, query)
     if not len(rs):
         content = [self._render_template('fail/noSubjectHits.html',
                                          query=rs.query)
                    ]
     else:
         content = [self._render_template('subjectResults.html',
                                          resultSet=rs,
                                          maximumRecords=maximumRecords,
                                          startRecord=startRecord,
                                          )]
     session.database = 'db_ead'
     return content
示例#2
0
 def parse(self, session, data, codec, db):
     form = data
     qString = generate_cqlQuery(form)
     return cql.parse(qString)
示例#3
0
    def _get_query(self, form):
        session = self.session
        queryFactory = self.queryFactory
        qString = form.getvalue('query')
        rsid = form.getvalue('rsid', None)
        filter_ = form.getvalue('filter', '')
        withinContributor = form.getvalue('withinContributor', None)
        withinCollection = form.getvalue('withinCollection', None)
        if rsid:
            qString = self._fetch_query(session, rsid).toCQL()
        elif not qString:
            qString = generate_cqlQuery(form)
        if not isinstance(qString, unicode):
            qString = unicode(qString, 'utf-8')
        if filter_:
            if qString.strip('()'):
                qString = u'{0} and/relevant/proxinfo ({1})'.format(filter_,
                                                                    qString
                                                                    )
            else:
                qString = filter_

        if (withinCollection and withinCollection != 'allcollections'):
            if qString.strip(u'()'):
                qString = (u'(rec.collectionIdentifier exact "{0}") '
                           u'and/relevant/proxinfo '
                           u'({1})'.format(withinCollection,
                                           qString)
                           )
            else:
                qString = (u'rec.collectionIdentifier exact "{0}"'
                           u''.format(withinCollection))
        elif 'noComponents' in form:
            qString = (u'ead.istoplevel=1 and/relevant/proxinfo (%s)'
                       u'' % qString)

        if (withinContributor and withinContributor != 'allcontributors'):
            if qString.strip(u'()'):
                qString = (u'(vdb.identifier exact "{0}") '
                           u'and/relevant/proxinfo '
                           u'({1})'.format(withinContributor,
                                           qString)
                           )
            else:
                qString = (u'vdb.identifier exact "{0}"'
                           u''.format(withinContributor))

        if not qString.strip(u'()'):
            self._log(40, '*** Unable to generate CQL query')
            return self._render_template('fail/invalidQuery.html')

        try:
            return queryFactory.get_query(session,
                                          qString.encode('utf-8'),
                                          format="cql"
                                          )
        except CQLDiagnostic:
            self._log(40, '*** Unparsable query: %s' % qString)
            if (qString.count('"') % 2):
                return self._render_template('fail/unpairedQuotes.html')
            else:
                return self._render_template('fail/invalidQuery.html')
示例#4
0
 def parse(self, session, data, codec, db):
     form = data
     qString = generate_cqlQuery(form)
     return cql.parse(qString)