# -*- coding: utf-8 -*-
from django import forms
+from telemeta.models import *
from haystack.inputs import AutoQuery, Exact, Clean
-from haystack.forms import SearchForm
+from haystack.forms import *
from haystack.query import SearchQuerySet
-class HaySearchForm(SearchForm):
+class HaySearchFormItem(SearchForm):
def search(self):
sqs=SearchQuerySet().load_all()
return sqs
if self.cleaned_data['q']:
- sqs=sqs.filter(content__contains=self.cleaned_data['q'])
+ sqs=sqs.models(MediaItem).filter(content__contains=self.cleaned_data['q'])
+
+ return sqs
+
+class HaySearchFormCollection(SearchForm):
+
+ def search(self):
+ sqs=SearchQuerySet().load_all()
+
+ if not self.is_valid():
+ return sqs
+
+ if self.cleaned_data['q']:
+ sqs=sqs.models(MediaCollection).filter(content__contains=self.cleaned_data['q'])
return sqs
from telemeta.views.haystack_search import *
from haystack.query import SearchQuerySet
from haystack.views import SearchView
-from telemeta.forms.haystack_form import HaySearchForm
+from haystack.forms import *
+from telemeta.forms.haystack_form import HaySearchFormItem, HaySearchFormCollection
urlpatterns = patterns('',
- url(r'^$', SearchView(form_class=HaySearchForm), name='haystack_search'),
+ url(r'^$', HaystackSearchItem(form_class=HaySearchFormItem), name='haystack_search_item'),
+ url(r'^item/$', HaystackSearchItem(form_class=HaySearchFormItem), name='haystack_search_item'),
+ url(r'^collection/$', HaystackSearchCollection(form_class=HaySearchFormCollection), name='haystack_search_collection'),
)
return MediaItem
+class MediaCollectionIndex(indexes.SearchIndex, indexes.Indexable):
+
+ text = indexes.NgramField(document=True, use_template=True)
+ #rec_date = indexes.DateTimeField(use_template=True, null=True)
+
+ def get_model(self):
+ return MediaCollection
\ No newline at end of file
<a href="{% url "telemeta-item-detail" result.object.public_id %}">{{ result.object.title }}</a>
</td>
<td align="center">
- {% if result.file %}
+ {% if result.object.file %}
<a href="{% url "telemeta-item-detail" result.object.public_id %}">
<center><span class="glyphicon glyphicon-volume-up" style="font-size: 1.3em;"></span></center>
{% endif %}
{% if query %}
<h1>{% trans "Results" %}</h1>
- <div class="fullpage">
- {% include "search/mediaitem_listhaystack.html" %}
- </div>
-
- {% if page.has_previous or page.has_next %}
- <div>
- {% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
- |
- {% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
+ {% ifequal type 'item' %}
+ <p><b>Items ({{item_count}}) | <a href="{% url "haystack_search_collection" %}?q={{ query }}&page=1">Collections ({{collection_count}})</a></b></p>
+ {% else %}
+ {% ifequal type 'collection'%}
+ <p><b><a href="{% url "haystack_search_item" %}?q={{ query }}&page=1">Items ({{item_count}}) </a>| Collections ({{collection_count}})</b></p>
+ {% endifequal %}
+ {% endifequal %}
+ {% with object_list as items %}
+ <div class="fullpage">
+ {% include "search/mediaitem_listhaystack.html" %}
</div>
- {% endif %}
+
+ {% if page.has_previous or page.has_next %}
+ <div>
+ {% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
+ |
+ {% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
+ </div>
+ {% endif %}
+ {% endwith %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
from haystack.views import SearchView
from haystack.query import SearchQuerySet
+from telemeta.models import *
+from telemeta.forms.haystack_form import HaySearchFormItem, HaySearchFormCollection
-class HaystackSearch(SearchView):
+class HaystackSearchItem(SearchView):
def get_query(self):
- query=super(HaystackSearch, self).get_query()
- return query
+ return super(HaystackSearchItem, self).get_query()
+ def extra_context(self):
+ extra = super(HaystackSearchItem, self).extra_context()
+ extra['collection_count']=SearchQuerySet().load_all().models(MediaCollection).filter(content__contains=self.get_query()).count()
+ extra['item_count']=SearchQuerySet().load_all().models(MediaItem).filter(content__contains=self.get_query()).count()
+ extra['type']='item'
+ return extra
+class HaystackSearchCollection(SearchView):
+ def get_query(self):
+ return super(HaystackSearchCollection, self).get_query()
+
+ def extra_context(self):
+ extra = super(HaystackSearchCollection, self).extra_context()
+ extra['collection_count']=SearchQuerySet().load_all().models(MediaCollection).filter(content__contains=self.get_query()).count()
+ extra['item_count']=SearchQuerySet().load_all().models(MediaItem).filter(content__contains=self.get_query()).count()
+ extra['type']='collection'
+ return extra