49 | | * For enabling |
50 | | |
| 49 | * The code for asynchronously indexing documents is in ''models/tasks.py'' |
| 50 | * '''Insertion''': The code will first insert the document into the database. Then in callback ''onaccept'' it will index those documents calling the document_create_index() function from models/tasks.py . The following code should be added for enabling Full Text search for documents in any modules. The example is there, you can see modules/s3db/doc.py in document_onaccept() hook. |
| 51 | * '''Deletion''': The code will first delete the record from the database table, then will select that file and will delete it from Solr also, by deleting its index which is stored in solr server. You can look for the code in modules/s3db/doc.py in document_ondelete() hook. |
| 52 | * In model() |
| 53 | {{{ |
| 54 | |
| 55 | |
| 56 | if settings.get_base_solr_url(): |
| 57 | onaccept = self.document_onaccept # where document_onaccept is the onaccept hook for indexing |
| 58 | ondelete = self.document_ondelete # where document_onaccept is the onaccept hook for deleting |
| 59 | else: |
| 60 | onaccept = None |
| 61 | ondelete = None |
| 62 | |
| 63 | configure(tablename, |
| 64 | onaccept=onaccept, |
| 65 | ondelete=ondelete, |
| 66 | ..... |
| 67 | |
| 68 | |
| 69 | |
| 70 | }}} |
| 71 | * In onaccept() |
| 72 | {{{ |
| 73 | vars = form.vars |
| 74 | doc = vars.file # Where file is the name of the |
| 75 | |
| 76 | table = current.db.doc_document |
| 77 | try: |
| 78 | name = table.file.retrieve(doc)[0] |
| 79 | except TypeError: |
| 80 | name = doc |
| 81 | |
| 82 | document = json.dumps(dict(filename=doc, |
| 83 | name=name, |
| 84 | id=vars.id, |
| 85 | tablename="doc_document", |
| 86 | )) |
| 87 | |
| 88 | current.s3task.async("document_create_index", |
| 89 | args = [document]) |
| 90 | |
| 91 | return |
| 92 | |
| 93 | |
| 94 | |
| 95 | }}} |