7 from tagging.models import Tag |
7 from tagging.models import Tag |
8 from utils import generate_uuid |
8 from utils import generate_uuid |
9 import os.path |
9 import os.path |
10 import uuid |
10 import uuid |
11 import lxml |
11 import lxml |
|
12 import lucene |
|
13 from ldt.ldt_utils import STORE, ANALYZER |
|
14 from annotindexer import AnnotIndexer |
12 #from django.core.management.validation import max_length |
15 #from django.core.management.validation import max_length |
13 |
16 |
14 def Property(func): |
17 def Property(func): |
15 return property(**func()) |
18 return property(**func()) |
16 |
19 |
118 |
121 |
119 @staticmethod |
122 @staticmethod |
120 def create_annotation(external_id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None): |
123 def create_annotation(external_id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None): |
121 annotation = Annotation(external_id=external_id, uri=uri, tags=tags, title=title, description=description, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date) |
124 annotation = Annotation(external_id=external_id, uri=uri, tags=tags, title=title, description=description, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date) |
122 annotation.save() |
125 annotation.save() |
|
126 annotation.index_annot() |
123 |
127 |
124 return annotation |
128 return annotation |
125 |
129 |
|
130 |
|
131 def delete(self): |
|
132 super(Annotation, self).delete() |
|
133 lucene.getVMEnv().attachCurrentThread() |
|
134 writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED) |
|
135 writer.deleteDocuments(lucene.Term("external_id", self.external_id)) |
|
136 writer.close() |
|
137 |
|
138 def index_annot(self): |
|
139 lucene.getVMEnv().attachCurrentThread() |
|
140 writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED) |
|
141 annotl = [self,] |
|
142 indexer = AnnotIndexer(annotl,writer) |
|
143 indexer.index_all() |
|
144 writer.close() |
|
145 |
|
146 def update_index(self): |
|
147 lucene.getVMEnv().attachCurrentThread() |
|
148 writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED) |
|
149 writer.deleteDocuments(lucene.Term("external_id", self.external_id)) |
|
150 writer.close() |
|
151 self.index_annot() |
|
152 |
|
153 |