Example #1
0
    def test_filtering(self):
        self.assertTrue(Video.objects.count())
        for video in Video.objects.all():
            video_changed_tasks.delay(video.pk)

        reset_solr()

        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u' ', video_lang='en'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']

        self.assertTrue(len(result))
        for video in VideoIndex.public():
            if video.video_language == 'en':
                self.assertTrue(
                    video.object in [item.object for item in result])

        rdata = RpcMultiValueDict(dict(q=u' ', langs='en'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']

        self.assertTrue(len(result))
        for video in VideoIndex.public():
            if video.languages and 'en' in video.languages:
                self.assertTrue(
                    video.object in [item.object for item in result])
Example #2
0
    def test_empty_query(self):
        rpc = SearchApiClass()
        
        rdata = RpcMultiValueDict(dict(q=u''))
        rpc.search(rdata, self.user, testing=True)['sqs']

        rdata = RpcMultiValueDict(dict(q=u' '))
        rpc.search(rdata, self.user, testing=True)['sqs']
Example #3
0
    def test_query_clean(self):
        video = Video.objects.all()[0]
        video.title = u"Cher BBC and Dawn French's Lookalikes"
        video.save()
        reset_solr()
        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u'?BBC'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']
        self.assertTrue(len(result))
Example #4
0
 def test_query_clean(self):
     video = Video.objects.all()[0]
     video.title = u"Cher BBC and Dawn French's Lookalikes"
     video.save()
     reset_solr()
     rpc = SearchApiClass()
     
     rdata = RpcMultiValueDict(dict(q=u'?BBC'))
     result = rpc.search(rdata, self.user, testing=True)['sqs']
     self.assertTrue(len(result))        
Example #5
0
    def test_rpc(self):
        rpc = SearchApiClass()
        rdata = RpcMultiValueDict(dict(q=u'BBC'))

        for title in self.titles:
            video = Video.objects.all()[0]
            video.title = title
            video.save()
            reset_solr()

            result = rpc.search(rdata, self.user, testing=True)['sqs']
            self.assertTrue(video in [item.object for item in result], title)
Example #6
0
 def test_rpc(self):
     rpc = SearchApiClass()
     rdata = RpcMultiValueDict(dict(q=u'BBC'))
     
     for title in self.titles:
         video = Video.objects.all()[0]
         video.title = title
         video.save()
         reset_solr()
         
         result = rpc.search(rdata, self.user, testing=True)['sqs']
         self.assertTrue(video in [item.object for item in result], title)
Example #7
0
 def test_search_index_updating(self):
     reset_solr()
     rpc = SearchApiClass()
     
     for title in self.titles:
         rdata = RpcMultiValueDict(dict(q=title))
         video = Video.objects.all()[0]
         video.title = title
         video.save()
         video.update_search_index()
         
         result = rpc.search(rdata, self.user, testing=True)['sqs']
         self.assertTrue(video in [item.object for item in result], title)
Example #8
0
    def test_search_relevance(self):
        reset_solr()

        rpc = SearchApiClass()
        rdata = RpcMultiValueDict(dict(q=u'unique'))

        result = rpc.search(rdata, self.user, testing=True)['sqs']
        videos = [item.object for item in result]

        # by default, title is more important than description
        self.assertEquals(videos[0].title, u"This is my unique title")
        self.assertEquals(videos[1].title, u"Default")
        self.assertEquals(videos[1].description,
                          u"this is my unique description")
Example #9
0
    def test_empty_query(self):
        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u''))
        rpc.search(rdata, self.user, testing=True)['sqs']

        rdata = RpcMultiValueDict(dict(q=u' '))
        rpc.search(rdata, self.user, testing=True)['sqs']
Example #10
0
 def test_filtering(self):
     self.assertTrue(Video.objects.count())
     for video in Video.objects.all():
         video_changed_tasks.delay(video.pk)
     
     reset_solr()
     
     rpc = SearchApiClass()
     
     rdata = RpcMultiValueDict(dict(q=u' ', video_lang='en'))
     result = rpc.search(rdata, self.user, testing=True)['sqs']
     
     self.assertTrue(len(result))
     for video in SearchQuerySet().models(Video):
         if video.video_language == 'en':
             self.assertTrue(video.object in [item.object for item in result])
     
     rdata = RpcMultiValueDict(dict(q=u' ', langs='en'))
     result = rpc.search(rdata, self.user, testing=True)['sqs']
     
     self.assertTrue(len(result))
     for video in SearchQuerySet().models(Video):
         if video.languages and 'en' in video.languages:
             self.assertTrue(video.object in [item.object for item in result])        
Example #11
0
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see
# http://www.gnu.org/licenses/agpl-3.0.html.
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.http import urlencode

from search.forms import SearchForm
from search.rpc import SearchApiClass
from utils import render_to
from utils.context_processors import current_site
from utils.rpc import RpcRouter

rpc_router = RpcRouter('search:rpc_router', {'SearchApi': SearchApiClass()})


@render_to('search/search.html')
def index(request):
    if request.GET:
        site = current_site(request)
        query = {}
        for k, v in request.GET.items():
            query[k] = v
        # If we're at a URL with query params we just got here from a search
        # form on another page.  If that's the case, we'll redirect to the
        # AJAX-style URL with the params in the hash.  Then that page will take
        # the other branch of this if, and the search form will work its
        # frontend magic.
        url = '%s%s#/?%s' % (