def document(self, connection, retry=False): """ return a xapian index document from the context. we can introspect the connection to discover relevant fields available. """ doc = xappy.UnprocessedDocument() if interfaces.ENABLE_LOGGING: log.debug("Indexing Document %r" % self.context) # object type doc.fields.append(xappy.Field("object_type", self.context.__class__.__name__)) # object kind doc.fields.append(xappy.Field("object_kind", domain.object_hierarchy_type(self.context))) try: # TODO: loop thru all available languages and index the translations self.index(doc) except exceptions.OperationalError, exceptions.InvalidRequestError: # detatch the dbapi connection from the pool, and close it # and retry the index operation (once) log.error("Indexing Connection Hosed, Discarding") db_connection = metadata.bind.contextual_connect() db_connection.begin().rollback() db_connection.detach() db_connection.close() if not retry: return self.document(connection, retry=True) raise
def document(self, connection, retry=False): """ return a xapian index document from the context. we can introspect the connection to discover relevant fields available. """ doc = xappy.UnprocessedDocument() if interfaces.ENABLE_LOGGING: log.debug("Indexing Document %r" % self.context) # object type doc.fields.append( xappy.Field("object_type", self.context.__class__.__name__)) # object kind doc.fields.append( xappy.Field("object_kind", domain.object_hierarchy_type(self.context))) try: #TODO: loop thru all available languages and index the translations self.index(doc) except exceptions.OperationalError, exceptions.InvalidRequestError: # detatch the dbapi connection from the pool, and close it # and retry the index operation (once) log.error("Indexing Connection Hosed, Discarding") db_connection = metadata.bind.contextual_connect() db_connection.begin().rollback() db_connection.detach() db_connection.close() if not retry: return self.document(connection, retry=True) raise
def document(self, connection, retry=False): """ return a xapian index document from the context. we can introspect the connection to discover relevant fields available. """ doc = xappy.UnprocessedDocument() if interfaces.ENABLE_LOGGING: log.debug("Indexing Document %r"%self.context) # object type doc.fields.append( xappy.Field("object_type", self.context.__class__.__name__)) # object kind doc.fields.append( xappy.Field("object_kind", domain.object_hierarchy_type(self.context))) # object language doc.fields.append( xappy.Field("language", self.context.language)) doc.fields.append(xappy.Field("status", getattr(self.context, "status", ""))) doc.fields.append(xappy.Field("owner", str(getattr(self.context, "owner_id", "")))) try: status_date = getattr(self.context, "status_date") if status_date: status_date = date_value(status_date) doc.fields.append(xappy.Field("status_date", status_date)) except Exception: pass title = "" try: title = bungeni.ui.search.ISearchResult(self.context).title except Exception: pass doc.fields.append(xappy.Field("title", title)) try: #TODO: loop thru all available languages and index the translations self.index(doc) except exceptions.OperationalError, exceptions.InvalidRequestError: # detatch the dbapi connection from the pool, and close it # and retry the index operation (once) log.error("Indexing Connection Hosed, Discarding") db_connection = metadata.bind.contextual_connect() db_connection.begin().rollback() db_connection.detach() db_connection.close() if not retry: return self.document(connection, retry=True) raise
def document(self, connection, retry=False): """ return a xapian index document from the context. we can introspect the connection to discover relevant fields available. """ doc = xappy.UnprocessedDocument() if interfaces.ENABLE_LOGGING: log.debug("Indexing Document %r"%self.context) # object type doc.fields.append( xappy.Field("object_type", self.context.__class__.__name__)) # object kind doc.fields.append( xappy.Field("object_kind", domain.object_hierarchy_type(self.context))) # object language doc.fields.append( xappy.Field("language", self.context.language)) doc.fields.append(xappy.Field("status", getattr(self.context, "status", ""))) doc.fields.append(xappy.Field("owner", str(getattr(self.context, "owner_id", "")))) try: status_date = getattr(self.context, "status_date") if status_date: status_date = date_value(status_date) doc.fields.append(xappy.Field("status_date", status_date)) except Exception: pass title = "" try: title = bungeni.ui.search.ISearchResult(self.context).title except Exception: pass doc.fields.append(xappy.Field("title", title)) try: #TODO: loop thru all available languages and index the translations self.index(doc) except exceptions.OperationalError, exceptions.InvalidRequestError: # detatch the dbapi connection from the pool, and close it # and retry the index operation (once) log.error("Indexing Connection Hosed, Discarding") db_connection = metadata.bind.contextual_connect() db_connection.begin().rollback() db_connection.detach() db_connection.close() if not retry: return self.document(connection, retry=True) raise