Example #1
0
 def test_wildcard_search_cleaned_up(self):
     from adhocracy.lib.search.query import add_wildcard_query
     search = SolrSearch(interface)
     query = add_wildcard_query(search, 'text', 'one** two*')
     self.assertEqual(
         query.params(),
         [('q', '(text:one OR text:one*) AND (text:two OR text:two*)')])
Example #2
0
    def test_wildcard_search_ignore_none(self):
        from adhocracy.lib.search.query import add_wildcard_query
        search = SolrSearch(interface)

        query = add_wildcard_query(search, 'text', None)
        self.assertEqual(
            query.params(),
            [('q', '*:*')])
Example #3
0
    def test_wildcard_search_added_to_search(self):
        from adhocracy.lib.search.query import add_wildcard_query
        search = SolrSearch(interface).query(text='passedin')

        query = add_wildcard_query(search, 'text', 'wild')
        self.assertEqual(
            query.params(),
            [('q', 'text:passedin AND (text:wild OR text:wild*)')])
Example #4
0
    def __init__(self, name, itemfunc, entity_type=None, extra_filter=None,
                 initial_size=20, size=None, sorts=None,
                 enable_sorts=True, enable_pages=True, facets=tuple(),
                 wildcard_queries=None):
        self.name = name
        self.itemfunc = itemfunc
        self.enable_pages = enable_pages
        self.extra_filter = extra_filter
        self.facets = [Facet(self.name, request) for Facet in facets]
        self.wildcard_queries = wildcard_queries or {}
        self.initial_size = initial_size
        if size is not None:
            self.size = size
        elif c.user and c.user.page_size:
            self.size = c.user.page_size
        else:
            self.size = initial_size
        self.size = self._get_size()

        self.enable_sorts = enable_sorts
        self.sorts = sorts
        self.sorts.set_pager(pager=self)
        if self.sorts:
            self.selected_sort = self.sorts.selected().value

        self.page = self._get_page()

        ## build the query
        query = sunburnt_query(entity_type)
        if self.extra_filter:
            query = query.filter(**self.extra_filter)
        for field, string in self.wildcard_queries.items():
            query = add_wildcard_query(query, field, string)

        # Add facets
        counts_query = query
        counts_query = counts_query.paginate(rows=0)
        query.faceter.update(limit='65000')
        counts_query.faceter.update(limit='65000')
        for facet in self.facets:
            query, counts_query = facet.add_to_queries(query, counts_query)

        # Add pagination and sorting
        if enable_pages:
            query = query.paginate(start=self.offset, rows=self.size)

        if self.selected_sort is not None:
            query = query.sort_by(self.selected_sort)

        # query solr and calculate values from it
        self.response = query.execute()
        self.counts_response = counts_query.execute()
        # if we are out of the page range do a permanent redirect
        # to the last page
        if (self.pages > 0) and (self.page > self.pages):
            new_url = self.build_url(page=self.pages)
            redirect(new_url, code=301)

        for facet in self.facets:
            facet.update(self.response, self.counts_response)
        self.items = self._items_from_response(self.response)
Example #5
0
    def __init__(self,
                 name,
                 itemfunc,
                 entity_type=None,
                 extra_filter=None,
                 initial_size=20,
                 size=None,
                 sorts=None,
                 enable_sorts=True,
                 enable_pages=True,
                 facets=tuple(),
                 wildcard_queries=None):
        self.name = name
        self.itemfunc = itemfunc
        self.enable_pages = enable_pages
        self.extra_filter = extra_filter
        self.facets = [Facet(self.name, request) for Facet in facets]
        self.wildcard_queries = wildcard_queries or {}
        self.initial_size = initial_size
        if size is not None:
            self.size = size
        elif c.user and c.user.page_size:
            self.size = c.user.page_size
        else:
            self.size = initial_size
        self.size = self._get_size()

        self.enable_sorts = enable_sorts
        self.sorts = sorts
        self.sorts.set_pager(pager=self)
        if self.sorts:
            self.selected_sort = self.sorts.selected().value

        self.page = self._get_page()

        ## build the query
        query = sunburnt_query(entity_type)
        if self.extra_filter:
            query = query.filter(**self.extra_filter)
        for field, string in self.wildcard_queries.items():
            query = add_wildcard_query(query, field, string)

        # Add facets
        counts_query = query
        counts_query = counts_query.paginate(rows=0)
        query.faceter.update(limit='65000')
        counts_query.faceter.update(limit='65000')
        for facet in self.facets:
            query, counts_query = facet.add_to_queries(query, counts_query)

        # Add pagination and sorting
        if enable_pages:
            query = query.paginate(start=self.offset, rows=self.size)

        if self.selected_sort is not None:
            query = query.sort_by(self.selected_sort)

        # query solr and calculate values from it
        self.response = query.execute()
        self.counts_response = counts_query.execute()
        # if we are out of the page range do a permanent redirect
        # to the last page
        if (self.pages > 0) and (self.page > self.pages):
            new_url = self.build_url(page=self.pages)
            redirect(new_url, code=301)

        for facet in self.facets:
            facet.update(self.response, self.counts_response)
        self.items = self._items_from_response(self.response)