Exemple #1
0
 def get_results(self):
     starttime = datetime.now()
     sqs = super(MetashareFacetedSearchView, self).get_results()
     if not self.request.user.is_staff:
         sqs = sqs.filter(published=True)
     if (len(sqs) > 0 and len(self.query) > 0):
         saveQueryStats(self.request.user.username, '', self.query, len(sqs), (datetime.now() - starttime).microseconds)
     return sqs
Exemple #2
0
 def test_latest_queries(self):
     """
     Test whether there are latest queries
     """
     saveQueryStats("tesQuerytquery 001", "", 10)
     saveQueryStats("tesQuerytquery 002", "", 2)
     latest_query = getLastQuery(2)
     client = Client()
     _url = "/{0}stats/top/?view=latestqueries".format(DJANGO_BASE)
     response = client.get(_url)
     self.assertContains(response, 'META-SHARE node visits statistics')
     self.assertContains(response, 'http://')
     self.assertGreaterEqual(len(latest_query), 1)
     for item in latest_query:
         self.assertContains(response, item['query'])
Exemple #3
0
 def testLatestQueries(self):
     """
     Test whether there are latest queries
     """
     saveQueryStats("anonymous", "testquery 000", 1, 0)
     latest_query = getLastQuery(2)
     client = Client()
     _url = "/{0}stats/top/?view=latestqueries".format(DJANGO_BASE)
     response = client.get(_url)
     self.assertEquals(200, response.status_code)
     self.assertContains(response, 'Top 10')
     self.assertContains(response, 'http://')
     self.assertGreaterEqual(len(latest_query), 1)
     for item in latest_query:
         self.assertContains(response, item['query'])
Exemple #4
0
    def get_results(self):
        sqs = super(MetashareFacetedSearchView, self).get_results()

        # Sort the results (on only one sorting value)
        if 'sort' in self.request.GET:
            sort_list = self.request.GET.getlist('sort')
            
            if sort_list[0] == 'resourcename_asc':
                sqs = sqs.order_by('resourceNameSort_exact')
            elif sort_list[0] == 'resourcename_desc':
                sqs = sqs.order_by('-resourceNameSort_exact')
            elif sort_list[0] == 'resourcetype_asc':
                sqs = sqs.order_by('resourceTypeSort_exact')
            elif sort_list[0] == 'resourcetype_desc':
                sqs = sqs.order_by('-resourceTypeSort_exact')
            elif sort_list[0] == 'mediatype_asc':
                sqs = sqs.order_by('mediaTypeSort_exact')
            elif sort_list[0] == 'mediatype_desc':
                sqs = sqs.order_by('-mediaTypeSort_exact')
            elif sort_list[0] == 'languagename_asc':
                sqs = sqs.order_by('languageNameSort_exact')
            elif sort_list[0] == 'languagename_desc':
                sqs = sqs.order_by('-languageNameSort_exact')
            elif sort_list[0] == 'dl_count_desc':
                sqs = sqs.order_by('-dl_count', 'resourceNameSort_exact')
            elif sort_list[0] == 'view_count_desc':
                sqs = sqs.order_by('-view_count', 'resourceNameSort_exact')
            else:
                sqs = sqs.order_by('resourceNameSort_exact')
        else:
            sqs = sqs.order_by('resourceNameSort_exact')

        # collect statistics about the query
        starttime = datetime.now()
        results_count = 0
        for r in sqs:
            if r != None:
                results_count += 1
        if self.query:
            saveQueryStats(self.query, \
                str(sorted(self.request.GET.getlist("selected_facets"))), \
                           results_count, \
                           (datetime.now() - starttime).microseconds, self.request)
        return sqs
Exemple #5
0
    def get_results(self):
        sqs = super(MetashareFacetedSearchView, self).get_results()

        # Sort the results (on only one sorting value)
        if 'sort' in self.request.GET:
            sort_list = self.request.GET.getlist('sort')
            
            if sort_list[0] == 'resourcename_asc':
                sqs = sqs.order_by('resourceNameSort_exact')
            elif sort_list[0] == 'resourcename_desc':
                sqs = sqs.order_by('-resourceNameSort_exact')
            elif sort_list[0] == 'resourcetype_asc':
                sqs = sqs.order_by('resourceTypeSort_exact')
            elif sort_list[0] == 'resourcetype_desc':
                sqs = sqs.order_by('-resourceTypeSort_exact')
            elif sort_list[0] == 'mediatype_asc':
                sqs = sqs.order_by('mediaTypeSort_exact')
            elif sort_list[0] == 'mediatype_desc':
                sqs = sqs.order_by('-mediaTypeSort_exact')
            elif sort_list[0] == 'languagename_asc':
                sqs = sqs.order_by('languageNameSort_exact')
            elif sort_list[0] == 'languagename_desc':
                sqs = sqs.order_by('-languageNameSort_exact')
            elif sort_list[0] == 'dl_count_desc':
                sqs = sqs.order_by('-dl_count', 'resourceNameSort_exact')
            elif sort_list[0] == 'view_count_desc':
                sqs = sqs.order_by('-view_count', 'resourceNameSort_exact')
            else:
                sqs = sqs.order_by('resourceNameSort_exact')
        else:
            sqs = sqs.order_by('resourceNameSort_exact')

        # collect statistics about the query
        starttime = datetime.now()
        results_count = sqs.count()
        if self.query:
            saveQueryStats(self.query, \
                str(sorted(self.request.GET.getlist("selected_facets"))), \
                results_count, \
                (datetime.now() - starttime).microseconds, self.request)

        return sqs
Exemple #6
0
    def get_results(self):
        sqs = super(MetashareFacetedSearchView, self).get_results()
        if not self.request.user.is_staff:
            sqs = sqs.filter(published=True)

        # Sort the results (on only one sorting value)
        if 'sort' in self.request.GET:
            sort_list = self.request.GET.getlist('sort')
            
            if sort_list[0] == 'resourcename_asc':
                sqs = sqs.order_by('resourceNameSort_exact')
            elif sort_list[0] == 'resourcename_desc':
                sqs = sqs.order_by('-resourceNameSort_exact')
            elif sort_list[0] == 'resourcetype_asc':
                sqs = sqs.order_by('resourceTypeSort_exact')
            elif sort_list[0] == 'resourcetype_desc':
                sqs = sqs.order_by('-resourceTypeSort_exact')
            elif sort_list[0] == 'mediatype_asc':
                sqs = sqs.order_by('mediaTypeSort_exact')
            elif sort_list[0] == 'mediatype_desc':
                sqs = sqs.order_by('-mediaTypeSort_exact')
            elif sort_list[0] == 'languagename_asc':
                sqs = sqs.order_by('languageNameSort_exact')
            elif sort_list[0] == 'languagename_desc':
                sqs = sqs.order_by('-languageNameSort_exact')
            else:
                sqs = sqs.order_by('resourceNameSort_exact')
        else:
            sqs = sqs.order_by('resourceNameSort_exact')

        # collect statistics about the query
        starttime = datetime.now()
        results_count = sqs.count()
        if results_count and self.query:
            saveQueryStats(self.request.user.username, '', self.query,
                results_count, (datetime.now() - starttime).microseconds)

        return sqs