Enable search by author.
authorcavaliet
Thu, 08 Mar 2012 18:16:14 +0100
changeset 602 642b3654b8f1
parent 601 ae287132c61e
child 603 37c81c68ccf6
Enable search by author.
.hgignore
src/ldt/ldt/indexation/__init__.py
src/ldt/ldt/ldt_utils/contentindexer.py
src/ldt/ldt/ldt_utils/views/front.py
src/ldt/ldt/ldt_utils/views/workspace.py
--- a/.hgignore	Wed Mar 07 12:47:42 2012 +0100
+++ b/.hgignore	Thu Mar 08 18:16:14 2012 +0100
@@ -51,4 +51,6 @@
 syntax: regexp
 ^web/static/media/cache$
 syntax: regexp
-^\.settings/org\.eclipse\.core\.resources\.prefs$
\ No newline at end of file
+^\.settings/org\.eclipse\.core\.resources\.prefs$
+syntax: regexp
+^web/static/media/thumbnails$
\ No newline at end of file
--- a/src/ldt/ldt/indexation/__init__.py	Wed Mar 07 12:47:42 2012 +0100
+++ b/src/ldt/ldt/indexation/__init__.py	Thu Mar 08 18:16:14 2012 +0100
@@ -16,7 +16,6 @@
     
     try:
         res = get_results_list(field, query, searcher)
-        query = get_query_parser(field).parse(query)
         contexts = []
         content_iri_ids = None
         if content_list is not None :
@@ -32,7 +31,7 @@
                 tags = doc.getField('tags').stringValue()
                 begin = doc.getField('begin').stringValue()
                 duration = doc.getField('duration').stringValue()
-        
+                
                 ids['context'] = desc
                 ids['title'] = title
                 ids['tags'] = tags
--- a/src/ldt/ldt/ldt_utils/contentindexer.py	Wed Mar 07 12:47:42 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/contentindexer.py	Thu Mar 08 18:16:14 2012 +0100
@@ -99,13 +99,14 @@
                 doc.add(lucene.Field("project_id", ldt_id, lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED))
                 doc.add(lucene.Field("ensemble_id", ensembleId, lucene.Field.Store.YES, lucene.Field.Index.NO))
                 doc.add(lucene.Field("decoupage_id", decoupId, lucene.Field.Store.YES, lucene.Field.Index.NO))
-                doc.add(lucene.Field("element_id", elementId, lucene.Field.Store.YES, lucene.Field.Index.NO))                        
+                doc.add(lucene.Field("element_id", elementId, lucene.Field.Store.YES, lucene.Field.Index.NO))
                 doc.add(lucene.Field("tags", tags, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))
                 doc.add(lucene.Field("title", title, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))
                 doc.add(lucene.Field("abstract", abstract, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))
-                doc.add(lucene.Field("all", " ".join([tags, title, abstract]), lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))        
+                doc.add(lucene.Field("all", " ".join([tags, title, abstract]), lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))
                 doc.add(lucene.Field("begin", str(start_ts), lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED))
                 doc.add(lucene.Field("duration", str(duration), lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED))
+                doc.add(lucene.Field("author", author, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED))
 
                 seg = Segment(content=content,
                               iri_id=content.iri_id,
--- a/src/ldt/ldt/ldt_utils/views/front.py	Wed Mar 07 12:47:42 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Thu Mar 08 18:16:14 2012 +0100
@@ -127,7 +127,7 @@
     results = []
     search = ''
     field = 'all'
-    content_tag = 'all'
+    content_tag = None
     
     sform = SearchForm(request.GET)
     if sform.is_valid():
--- a/src/ldt/ldt/ldt_utils/views/workspace.py	Wed Mar 07 12:47:42 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/workspace.py	Thu Mar 08 18:16:14 2012 +0100
@@ -176,6 +176,15 @@
         
  
 def get_search_results(request, search, field, page, content_list=None):
+    # We parse the author if necessary. For author search to work in every case, we have to transform the query author:cheese shop into author:"CHEESE SHOP"
+    if u'author:' in search.lower() :
+        sub = search[7:]
+        sub = sub.upper()
+        if sub[0] != u'"':
+            sub = u'"' + sub
+        if sub[-1] != u'"':
+            sub = sub + u'"'
+        search = u'author:' + sub
     results = get_results_with_context(field, search, content_list)
             
     all_segments = Segment.objects.filter(element_id__in=[e['element_id'] for e in results])