]> git.parisson.com Git - telemeta.git/commitdiff
Add new index for autocomplete + locations in autocomplete
authormathieu <mathieu.boye28@gmail.com>
Wed, 11 May 2016 15:42:02 +0000 (17:42 +0200)
committermathieu <mathieu.boye28@gmail.com>
Wed, 11 May 2016 15:42:02 +0000 (17:42 +0200)
app/settings.py
telemeta/search_indexes.py
telemeta/templates/search/indexes/telemeta/location_text.txt [new file with mode: 0644]
telemeta/views/search.py

index ee965244b2c85456a7f49fbbade7507d6bb95d87..2b0c90c88e2fe3fe8cceeb7c786775c9eb7595d3 100644 (file)
@@ -306,6 +306,19 @@ HAYSTACK_CONNECTIONS = {
         'URL': 'http://search:9200/',
         'INDEX_NAME': 'haystack',
         'INLUDE_SPELLING': True,
+        'EXCLUDED_INDEXES': ['telemeta.search_indexes.LocationIndex']
+    },
+    'autocomplete': {
+        # 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
+        'ENGINE': 'telemeta.util.backend.CustomElasticEngine',
+        'URL': 'http://search:9200/',
+        'INDEX_NAME': 'haystackauto',
+        'INLUDE_SPELLING': True,
+        'EXCLUDED_INDEXES': ['telemeta.search_indexes.MediaItemIndex',
+                             'telemeta.search_indexes.MediaCollectionIndex',
+                             'telemeta.search_indexes.MediaCorpusIndex',
+                             'telemeta.search_indexes.MediaFondsIndex'
+                             ]
     },
 }
 HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
index 9d767a7e66c5be838771fa12e5d8101d02d8f44a..b8fb98c146f39abb82aae390f24cf91a263276a7 100644 (file)
@@ -239,7 +239,13 @@ class MediaFondsIndex(indexes.SearchIndex, indexes.Indexable):
     def get_model(self):
         return MediaFonds
 
-#class LocationIndex(indexes.SearchIndex, indexes.Indexable):
+class LocationIndex(indexes.SearchIndex, indexes.Indexable):
 
-#    text = indexes.CharField(document=True, use_template=True)
+    text = indexes.CharField(document=True, use_template=True)
+
+    def get_model(self):
+        return Location
+
+    def index_queryset(self, using=None):
+        return MediaItem.objects.all().locations()
 
diff --git a/telemeta/templates/search/indexes/telemeta/location_text.txt b/telemeta/templates/search/indexes/telemeta/location_text.txt
new file mode 100644 (file)
index 0000000..28701c1
--- /dev/null
@@ -0,0 +1 @@
+{{ object.name }}
\ No newline at end of file
index 33d173f799b03496ee3f5c7d9bfbadbab8b3b40a..475d3eecbd37af9e0c88654392cd545c523d2946 100644 (file)
@@ -167,14 +167,14 @@ class HaystackAdvanceSearch(SavedSearchView):
 
 def autocomplete(request):
     sqs = SearchQuerySet().load_all()
-    if request.GET.get('attr', '') == "instruments" or request.GET.get('attr', '') == "location":
+    if request.GET.get('attr', '') == "instruments":
         if request.GET.get('attr', '') == "instruments":
             sqs = sqs.filter(instruments__startswith=request.GET.get('q', ''))
             objets = [result.instruments for result in sqs]
             #instrus = [result.instruments for result in sqs]
-        elif request.GET.get('attr', '') == "location":
-             sqs = sqs.filter(SQ(location_principal__startswith=request.GET.get('q', ''))|SQ(location_relation__startswith=request.GET.get('q', '')))
-             objets = [result.location_principal+result.location_relation for result in sqs]
+        #elif request.GET.get('attr', '') == "location":
+        #     sqs = sqs.filter(SQ(location_principal__startswith=request.GET.get('q', ''))|SQ(location_relation__startswith=request.GET.get('q', '')))
+        #     objets = [result.location_principal+result.location_relation for result in sqs]
         suggestions = []
         for chaine in objets :
         #for chaine in instrus:
@@ -193,6 +193,9 @@ def autocomplete(request):
             for word in chaine.split('; '):
                 if word != "" and escapeAccentAndLower(request.GET.get('q', '')) in escapeAccentAndLower(word):
                     suggestions.append(word)
+    elif request.GET.get('attr', '') == "location":
+        sqs = SearchQuerySet().using('autocomplete').filter(content__startswith=request.GET.get('q', ''))
+        suggestions = [obj.text for obj in sqs]
     else:
         suggestions = []