Exemple #1
0
 def create_page(self, document, text, number=1):
     record = DocumentRecord()
     record.document_id = document.id
     record.text = text
     record.index = number
     db.session.add(record)
     return record
Exemple #2
0
 def emit_page(self, index, text):
     """Emit a plain text page."""
     record = DocumentRecord()
     record.document_id = self.document.id
     record.text = safe_string(text)
     record.index = index
     db.session.add(record)
Exemple #3
0
 def emit_page(self, index, text):
     """Emit a plain text page."""
     record = DocumentRecord()
     record.document_id = self.document.id
     record.text = safe_string(text)
     record.index = index
     db.session.add(record)
Exemple #4
0
 def emit_page(self, index, text):
     """Emit a plain text page."""
     self.document.type = Document.TYPE_TEXT
     record = DocumentRecord()
     record.document_id = self.document.id
     record.text = text
     record.index = index
     db.session.add(record)
Exemple #5
0
 def emit_page(self, index, text):
     """Emit a plain text page."""
     text = stringify(text)
     record = DocumentRecord()
     record.document_id = self.document.id
     record.text = text
     record.index = index
     db.session.add(record)
     if text is not None:
         self.pages.append(text)
Exemple #6
0
def record(document_id, index):
    enable_cache()
    document = get_document(document_id)
    record = DocumentRecord.by_index(document.id, index)
    if record is None:
        raise NotFound("No such record: %s" % index)
    return jsonify(record, schema=RecordSchema)
Exemple #7
0
 def __init__(self, request, parser, result, schema=None):
     super(RecordsQueryResult, self).__init__(request, parser, result,
                                              schema=schema)
     ids = [res.get('id') for res in self.results]
     for record in DocumentRecord.find_records(ids):
         for result in self.results:
             if result['id'] == record.id:
                 result['data'] = record.data
                 result['text'] = record.text
Exemple #8
0
def record(document_id, index):
    enable_cache()
    document = get_document(document_id)
    if not document.has_records():
        raise BadRequest("This document does not have records.")
    record = DocumentRecord.by_index(document.id, index)
    if record is None:
        raise NotFound("No such record: %s" % index)
    return jsonify(record, schema=RecordSchema)
Exemple #9
0
def record(document_id, index):
    enable_cache()
    document = get_db_document(document_id)
    if not document.supports_records:
        raise BadRequest("This document does not have records.")
    record = DocumentRecord.by_index(document.id, index)
    if record is None:
        raise NotFound("No such record: %s" % index)
    return serialize_data(record, RecordSchema)
Exemple #10
0
def execute_records_query(document_id, state, query):
    """Execute a query against records and return a set of results."""
    result, hits, output = execute_basic(TYPE_RECORD, query)
    ids = []
    for rec in hits.get('hits', []):
        record = rec.get('_source')
        record['score'] = rec.get('_score')
        record['id'] = int(rec.get('_id'))
        ids.append(rec.get('_id'))
        for text in rec.get('highlight', {}).get('text', []):
            record['text'] = text
        output['results'].append(record)

    for record in DocumentRecord.find_records(document_id, ids):
        for result in output['results']:
            if result['id'] == record.id:
                result['data'] = record.data
                result['text'] = record.text
    return output
def execute_records_query(document_id, state, query):
    """Execute a query against records and return a set of results."""
    result, hits, output = execute_basic(TYPE_RECORD, query)
    rows = []
    for rec in hits.get('hits', []):
        record = rec.get('_source')
        record['score'] = rec.get('_score')
        if record.get('row_id'):
            rows.append((record.get('sheet'), record.get('row_id')))

        for text in rec.get('highlight', {}).get('text', []):
            record['text'] = text
        output['results'].append(record)

    for record in DocumentRecord.find_rows(document_id, rows):
        for res in output['results']:
            if res['sheet'] == record.sheet and res['row_id'] == record.row_id:
                res['data'] = record.data
    return output
Exemple #12
0
 def emit_rows(self, iterator):
     """Emit rows of a tabular iterator."""
     iterator = self._emit_iterator_rows(iterator)
     DocumentRecord.insert_records(self.document.id, iterator)
Exemple #13
0
 def emit_rows(self, iterator):
     """Emit rows of a tabular iterator."""
     iterator = self._emit_iterator_rows(iterator)
     DocumentRecord.insert_records(self.document.id, iterator)