--- a/web/ldt/text/__init__.py Thu Dec 16 14:55:25 2010 +0100
+++ b/web/ldt/text/__init__.py Thu Dec 16 15:00:30 2010 +0100
@@ -1,2 +1,16 @@
+import lucene
+from django.conf import settings
+
+lucene.initVM(lucene.CLASSPATH)
+
+STORE = lucene.SimpleFSDirectory(lucene.File(settings.INDEX_PATH))
+ANALYZER = lucene.PerFieldAnalyzerWrapper(lucene.StandardAnalyzer(lucene.Version.LUCENE_CURRENT))
+ANALYZER.addAnalyzer("tags",lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
+ANALYZER.addAnalyzer("title",lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
+ANALYZER.addAnalyzer("abstract",lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
+ANALYZER.addAnalyzer("all",lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
+ANALYZER.addAnalyzer("type_doc",lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
+
+
VERSION = (1,0)
VERSION_STR = unicode(".".join(map(lambda i:"%01d" % (i,), VERSION)))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/ldt/text/annotindexer.py Thu Dec 16 15:00:30 2010 +0100
@@ -0,0 +1,46 @@
+from django.conf import settings
+from models import *
+import lucene
+from ldt.text import STORE
+from ldt.text import ANALYZER
+import lxml.etree
+
+
+class AnnotIndexer(object):
+
+ def __init__(self, annotList, writer):
+ self.__annotList = annotList
+ self.__writer = writer
+
+
+ def index_all(self):
+ for annot in self.__annotList:
+ self.index_annotation(annot)
+
+
+ def index_annotation(self, annotation):
+
+ doc = lucene.Document()
+
+ doc.add(lucene.Field("annotation_id", annotation.external_id, lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED))
+
+ annottags = annotation.get_tag_list()
+ tags = ""
+
+ if annottags is None or len(annottags) == 0:
+ tags = ""
+ else:
+ for tag in annottags:
+ tags += tag + ";"
+
+ doc.add(lucene.Field("type_doc", "text-annotation", lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+ doc.add(lucene.Field("tags", tags, lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+ doc.add(lucene.Field("title", annotation.title, lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+ doc.add(lucene.Field("abstract", annotation.description, lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+ doc.add(lucene.Field("text", annotation.text, lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+ doc.add(lucene.Field("all", " ".join([tags, annotation.title, annotation.description, annotation.text]), lucene.Field.Store.NO, lucene.Field.Index.ANALYZED))
+
+ self.__writer.addDocument(doc)
+
+ self.__writer.close()
+
\ No newline at end of file
--- a/web/ldt/text/models.py Thu Dec 16 14:55:25 2010 +0100
+++ b/web/ldt/text/models.py Thu Dec 16 15:00:30 2010 +0100
@@ -9,6 +9,9 @@
import os.path
import uuid
import lxml
+import lucene
+from ldt.ldt_utils import STORE, ANALYZER
+from annotindexer import AnnotIndexer
#from django.core.management.validation import max_length
def Property(func):
@@ -120,6 +123,31 @@
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):
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)
annotation.save()
+ annotation.index_annot()
return annotation
+
+ def delete(self):
+ super(Annotation, self).delete()
+ lucene.getVMEnv().attachCurrentThread()
+ writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
+ writer.deleteDocuments(lucene.Term("external_id", self.external_id))
+ writer.close()
+
+ def index_annot(self):
+ lucene.getVMEnv().attachCurrentThread()
+ writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
+ annotl = [self,]
+ indexer = AnnotIndexer(annotl,writer)
+ indexer.index_all()
+ writer.close()
+
+ def update_index(self):
+ lucene.getVMEnv().attachCurrentThread()
+ writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
+ writer.deleteDocuments(lucene.Term("external_id", self.external_id))
+ writer.close()
+ self.index_annot()
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/ldt/text/tests.py Thu Dec 16 15:00:30 2010 +0100
@@ -0,0 +1,234 @@
+#encoding:UTF-8
+
+""" Run these tests with 'python manage.py test text' """
+
+from django.test import TestCase
+import unittest
+import lxml.etree
+from ldt.text.models import *
+from ldt.core.models import Owner
+from views import *
+import urllib
+import uuid
+import tempfile
+import datetime
+from django.contrib.auth.models import *
+from django.conf import settings
+from django.test.client import Client
+from ldt.text import VERSION_STR
+from django.db import transaction
+from django.contrib.auth.models import User
+import time
+import lucene
+from ldt.text import STORE, ANALYZER
+from ldt.text.utils import *
+
+
+# This test creates an annotation and checks that:
+# 1. the annotation was created in the database (by trying to access it through a 'get')
+# 2. the returned xml contains correct data
+class CreateTest(unittest.TestCase):
+ def setUp(self):
+ self.content = str('<iri><text-annotation><id>f2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>')
+ self.c = Client()
+ self.annot = Annotation(external_id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=u"tag1,tag2", title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
+ self.annot.save()
+ def tearDown(self):
+ transaction.rollback()
+ annotlist=Annotation.objects.all()
+ for annot in annotlist:
+ annot.delete()
+
+ def test_create_annotation(self):
+ response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':self.content})
+ #self.assertEqual(response.content, " ")
+ self.annot1 = lxml.etree.fromstring(response.content)
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],"f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content")
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],u"tag1")
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation")
+ #self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550")
+ response2 = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'f2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ annot2 = lxml.etree.fromstring(response.content)
+ self.assertEqual(annot2.xpath("/iri/text-annotation/uri/text()")[0], "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
+
+ def test_error_create(self):
+ content = '<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>'
+ response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content})
+ self.assertEqual(response.status_code, 409)
+
+
+# This test creates an annotation, then gets it, and checks that the returned xml contains correct data
+class GetTest(unittest.TestCase):
+ def setUp(self):
+ self.annotation = Annotation(external_id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=u"tag1 ,tag2 , tag3", title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06 12:33:53.417550", update_date="2010-09-06 12:33:53.420459")
+ self.annotation.save()
+ self.c = Client()
+ def tearDown(self):
+ annotlist=Annotation.objects.all()
+ for annot in annotlist:
+ annot.delete()
+
+ def test_get_annotation(self):
+ response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ print response
+ self.annot1 = lxml.etree.fromstring(response.content)
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.external_id)
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], "tag2")
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color)
+ self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0], str(self.annotation.creation_date))
+
+ def test_error_get(self):
+ response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
+ self.assertEqual(response.status_code,404)
+
+
+class FilterTest(unittest.TestCase):
+ def setUp(self):
+ self.annotation = Annotation(external_id="k2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
+ self.annotation.save()
+ self.annotation2 = Annotation(external_id="l2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation2",text="texte selectionne lors de la creation de l\'annotation2",color="#BBBBBB", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
+ self.annotation2.save()
+ self.annotation3 = Annotation(external_id="m2c1d1fa-629d-4520-a3d2-955b4f2582c0", title="titre3", text="texte3", color="#CCCCCC", uri="http://blabla", creator="wakimd")
+ self.annotation3.save()
+ self.c = Client()
+ def tearDown(self):
+ annotlist=Annotation.objects.all()
+ for annot in annotlist:
+ annot.delete()
+
+ def test_filter_annotation_creator_limit(self):
+ user = 'wakimd'
+ uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
+ limit= 1
+ response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'creator':user,'limit':limit})
+ doc = lxml.etree.fromstring(response.content)
+ cpt = 0
+ for elem in doc.xpath("/iri/text-annotation"):
+ cpt = cpt + 1
+ if limit is not None:
+ self.assertEqual(cpt,limit)
+ for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
+ self.assertEqual(elem,user)
+ for elem in doc.xpath("/iri/text-annotation/uri/text()"):
+ self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
+
+ def test_filter_annotation_uri(self):
+ uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
+ response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri})
+ doc = lxml.etree.fromstring(response.content)
+ for elem in doc.xpath("/iri/text-annotation/uri/text()"):
+ self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
+
+ def test_filter_annotation_filter(self):
+ uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
+ filter = 'lors'
+ limit = None
+ response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'filter':filter})
+ doc = lxml.etree.fromstring(response.content)
+ for elem in doc.xpath("/iri/text-annotation/content/text/text()"):
+ self.assertTrue('lors' in elem)
+ #for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
+ # self.assertEqual(elem,user)
+
+
+# This test creates an annotation, then deletes it, and checks that:
+# 1. the annotation doesn't exist anymore in the database (by trying to access it through a 'get')
+# 2. the returned xml contains no data
+class DeleteTest(unittest.TestCase):
+ def setUp(self):
+ self.annotation = Annotation(external_id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
+ self.annotation.save()
+ self.c = Client()
+ def tearDown(self):
+ annotlist=Annotation.objects.all()
+ for annot in annotlist:
+ annot.delete()
+
+
+ def test_delete_annotation(self):
+ id = urllib.urlencode({'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ f = urllib.urlopen("http://127.0.0.1:8000/api/1.0/text/delete/", id)
+ response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ doc = lxml.etree.fromstring(response.content)
+ self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[])
+ self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), [])
+ self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[])
+ self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[])
+ self.assertEqual(response2.status_code, 404)
+
+
+ def test_error_delete(self):
+ response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'})
+ self.assertEqual(response.status_code,404)
+
+
+# This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data
+class UpdateTest(unittest.TestCase):
+ def setUp(self):
+ self.annotation = Annotation(external_id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=u"tag1, mytag",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
+ self.annotation.save()
+ self.c = Client()
+ def tearDown(self):
+ annotlist=Annotation.objects.all()
+ for annot in annotlist:
+ annot.delete()
+
+ def test_update_annotation(self):
+ content = '<iri><text-annotation><id></id><uri></uri><tags><tag>tag1</tag><tag>tag2new</tag><tag>tag3</tag></tags><content><color>#DDDDDD</color><description><![CDATA[texte de description update]]></description><title></title><text><![CDATA[texte selectionne a nouveau lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>80cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created></created><creator></creator><creator-id></creator-id><modified>2010-11-06 12:33:53.420459</modified></meta></text-annotation></iri>'
+ response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+ doc = lxml.etree.fromstring(response.content)
+ #self.assertEqual(lxml.etree.tostring(doc), " ")
+ self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
+ self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "tag2new")
+ self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
+
+ def test_error_update(self):
+ content = '<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>'
+ response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'})
+ self.assertEqual(response.status_code,404)
+
+
+class OnServerGlobalTest(unittest.TestCase):
+ def setUp(self):
+ self.content = urllib.urlencode({'content':'<iri><text-annotation><id>mypersonnalid</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>'})
+ self.content2 = urllib.urlencode({'content':'<iri><text-annotation><id>mypersonnalid2</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#BBBBBB</color><description><![CDATA[texte de description2]]></description><title><![CDATA[titre de l\'annotation2]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation2]]></text></content><meta><contributor>wakimd</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>'})
+ self.id = urllib.urlencode({"id":"mypersonnalid"})
+ self.id2 = urllib.urlencode({"id":"mypersonnalid2"})
+ self.uri = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"})
+ self.filt1 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", "creator":"","limit":"","filter":""})
+ self.filt2 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168","creator":"wakimd","limit":"","filter":""})
+ self.up = urllib.urlencode({'content':'<iri><text-annotation><id></id><uri></uri><tags><tag>tag1</tag><tag>tag2new</tag><tag>tag3</tag></tags><content><color>#DDDDDD</color><description><![CDATA[texte de description update]]></description><title></title><text><![CDATA[texte selectionne a nouveau lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>80cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created></created><creator></creator><creator-id></creator-id><modified>2010-11-06 12:33:53.420459</modified></meta></text-annotation></iri>','id':'mypersonnalid'})
+ self.LS = LdtSearch()
+
+ def test_everything(self):
+ creation = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content)
+ creation2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content2)
+
+ res1 = self.LS.query("title","titre de l'annotation")
+ self.assertEqual(len(res1),1)
+ res2 = self.LS.query("title","titre de l'annotation2")
+ self.assertEqual(len(res2),1)
+
+
+ get = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/get/?%s" % self.id)
+
+ update = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/update/", self.up)
+
+ res3 = self.LS.query("abstract","texte de description update")
+ self.assertEqual(len(res3),1)
+
+ filt1 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?%s" % self.uri)
+ filt2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?uri=http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168?creator=wakimd")
+
+ delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id)
+ delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id2)
+
+ res4 = self.LS.query("title","titre de l'annotation")
+ self.assertEqual(len(res4),0)
+ res5 = self.LS.query("title","titre de l'annotation2")
+ self.assertEqual(len(res5),0)
+
+
+
--- a/web/ldt/text/utils.py Thu Dec 16 14:55:25 2010 +0100
+++ b/web/ldt/text/utils.py Thu Dec 16 15:00:30 2010 +0100
@@ -1,6 +1,8 @@
from django.conf import settings
+from ldt.ldt_utils import ANALYZER, STORE
import base64
import django.core.urlresolvers
+import lucene
import lxml.etree
import urllib
import uuid
@@ -36,3 +38,24 @@
return taglist
+
+class LdtSearch(object):
+
+ def query(self, field, query):
+ indexSearcher = lucene.IndexSearcher(STORE)
+ queryParser = lucene.QueryParser(lucene.Version.LUCENE_30, field, lucene.FrenchAnalyzer(lucene.Version.LUCENE_30))
+ queryParser.setDefaultOperator(lucene.QueryParser.Operator.AND)
+ queryObj = queryParser.parse(query)
+ hits = indexSearcher.search(queryObj, settings.LDT_MAX_SEARCH_NUMBER)
+
+ res = []
+ for hit in hits.scoreDocs:
+ doc = indexSearcher.doc(hit.doc)
+ res.append({"external_id":doc.get("external_id"),"title":doc.get("title")})
+ indexSearcher.close()
+ return res
+
+ def queryAll(self, query):
+ return self.query("all", query)
+
+
--- a/web/ldt/text/views.py Thu Dec 16 14:55:25 2010 +0100
+++ b/web/ldt/text/views.py Thu Dec 16 15:00:30 2010 +0100
@@ -44,11 +44,15 @@
query &= Q(uri=request.GET.get('uri'))
if request.GET.get('creator'):
query &= Q(creator=request.GET.get('creator'))
- if request.GET.get('filter') and len(request.GET.get('filter')) > 0:
- query &= Q(text__icontains=request.GET.get('filter'))
annotlist = Annotation.objects.filter(query)
+ if request.GET.get('filter') and len(request.GET.get('filter')) > 0:
+ search = LdtSearch()
+ res = search.query("all",request.GET.get('filter'))
+ for r in res:
+ annotlist.append(r)
+
if request.GET.get('limit'):
nb = request.GET.get('limit')
#offset = request.GET.get('limit')[1]
@@ -66,7 +70,6 @@
## Creates an annotation from a urlencoded xml content
## Returns an xml-structured annotation
-@oauth_required
@csrf_exempt
def create_annotation(request):
cont = request.POST["content"]
@@ -145,7 +148,6 @@
## Deletes an annotation (from its id)
## Returns an empty xml-structured annotation
-@oauth_required
@csrf_exempt
def delete_annotation(request):
try:
@@ -159,7 +161,6 @@
## Updates the content of an annotation
## Returns the xml-structured updated annotation
-@oauth_required
@csrf_exempt
def update_annotation(request):
try:
@@ -183,10 +184,7 @@
if len(tags) == 1:
tags_str += ","
annot.tags = tags_str
-
-
-
-
+
title = doc.xpath("/iri/text-annotation/content/title/text()")
if title and annot.title != title[0]:
annot.title = unicode(title[0])
@@ -208,6 +206,7 @@
annot.update_date = unicode(update_date[0])
annot.save()
+ annot.update_index()
return HttpResponse(lxml.etree.tostring(annot.serialize(), pretty_print=True), mimetype="text/xml;charset=utf-8")
--- a/web/leezam/urls.py Thu Dec 16 14:55:25 2010 +0100
+++ b/web/leezam/urls.py Thu Dec 16 15:00:30 2010 +0100
@@ -22,7 +22,6 @@
(r'^user/', include('ldt.user.urls')),
(r'^accounts/', include('registration.backends.simple.urls')),
- (r'^oauth/', include('oauth_provider.urls')),
(r'^/?$', 'django.views.generic.simple.redirect_to', {'url': 'api/'}),
)