def IndexDocuments(self, documents, response): """Indexes an iterable DocumentPb.Document.""" for document in documents: doc_id = document.id() if not doc_id: doc_id = str(uuid.uuid4()) document.set_id(doc_id) try: search._NewDocumentFromPb(document) except ValueError, e: new_status = response.add_status() new_status.set_code(search_service_pb.SearchServiceError.INVALID_REQUEST) new_status.set_error_detail(e.message) continue response.add_doc_id(doc_id) if doc_id in self._documents: old_document = self._documents[doc_id] self._inverted_index.RemoveDocument(old_document) self._documents[doc_id] = document new_status = response.add_status() new_status.set_code(search_service_pb.SearchServiceError.OK) self._inverted_index.AddDocument(doc_id, document)
def IndexDocuments(self, documents, response): """Indexes an iterable DocumentPb.Document.""" for document in documents: doc_id = document.id() if not doc_id: doc_id = str(uuid.uuid4()) document.set_id(doc_id) try: search._NewDocumentFromPb(document) except ValueError, e: new_status = response.add_status() new_status.set_code(search_service_pb.SearchServiceError.INVALID_REQUEST) new_status.set_error_detail(e.message) continue response.add_doc_id(doc_id) if doc_id in self._documents: old_document = self._documents[doc_id] self._inverted_index.RemoveDocument(old_document) self._documents[doc_id] = document new_status = response.add_status() new_status.set_code(search_service_pb.SearchServiceError.OK) self._inverted_index.AddDocument(doc_id, document)