'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'
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()
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:
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 = []