Beispiel #1
0
 def test_keyword_search_field_aliases(self):
     dqs = DocumentSolrQuerySet()
     with patch.object(dqs, "search") as mocksearch:
         dqs.keyword_search("pgpid:950 shelfmark:ena tag:state")
         mocksearch.return_value.raw_query_parameters.assert_called_with(
             keyword_query="pgpid_i:950 shelfmark_t:ena tags_ss_lower:state"
         )
Beispiel #2
0
 def test_admin_search(self):
     dqs = DocumentSolrQuerySet()
     with patch.object(dqs, "search") as mocksearch:
         dqs.admin_search("deed of sale")
         mocksearch.assert_called_with(dqs.admin_doc_qf)
         mocksearch.return_value.raw_query_parameters.assert_called_with(
             doc_query="deed of sale"
         )
Beispiel #3
0
 def test_keyword_search_shelfmark(self):
     dqs = DocumentSolrQuerySet()
     with patch.object(dqs, "search") as mocksearch:
         # ignore + when searching on joins
         dqs.keyword_search("CUL Or.1080 3.41 + T-S 13J16.20 + T-S 13J8.14")
         mocksearch.return_value.raw_query_parameters.assert_called_with(
             keyword_query="CUL Or.1080 3.41 T-S 13J16.20 T-S 13J8.14"
         )
Beispiel #4
0
 def get_queryset(self):
     return (
         DocumentSolrQuerySet()
         .filter(status=Document.PUBLIC_LABEL)
         .only("last_modified", "pgpid")
         .order_by("pgpid")
     )
Beispiel #5
0
    def get_queryset(self):

        # limit to documents with published status (i.e., no suppressed documents);
        # get counts of facets, excluding type filter
        documents = (DocumentSolrQuerySet().filter(
            status=Document.PUBLIC_LABEL).facet_field("type",
                                                      exclude="type",
                                                      sort="value"))

        form = self.get_form()
        # return empty queryset if not valid
        if not form.is_valid():
            documents = documents.none()

        # when form is valid, check for search term and filter queryset
        else:
            search_opts = form.cleaned_data

            if search_opts["q"]:
                # NOTE: using requireFieldMatch so that field-specific search
                # terms will NOT be usind for highlighting text matches
                # (unless they are in the appropriate field)
                documents = (
                    documents.keyword_search(search_opts["q"]).highlight(
                        "description",
                        snippets=3,
                        method="unified",
                        requireFieldMatch=True,
                    )
                    # return smaller chunk of highlighted text for transcriptions
                    # since the lines are often shorter, resulting in longer text
                    .highlight(
                        "transcription",
                        method="unified",
                        fragsize=150,  # try including more context
                        requireFieldMatch=True,
                    ).also("score"))  # include relevance score in results

            # order by sort option
            documents = documents.order_by(self.solr_sort[search_opts["sort"]])

            # filter by type if specified
            if search_opts["doctype"]:
                typelist = literal_eval(search_opts["doctype"])
                quoted_typelist = ['"%s"' % doctype for doctype in typelist]
                documents = documents.filter(type__in=quoted_typelist,
                                             tag="type")

        self.queryset = documents

        return documents
Beispiel #6
0
    def get_search_results(self, request, queryset, search_term):
        """Override admin search to use Solr."""

        # if search term is not blank, filter the queryset via solr search
        if search_term:
            # - use AND instead of OR to get smaller result sets, more
            #  similar to default admin search behavior
            # - return pks for all matching records
            sqs = (DocumentSolrQuerySet().admin_search(
                search_term).raw_query_parameters(**{
                    "q.op": "AND"
                }).only("pgpid").get_results(rows=100000))

            pks = [r["pgpid"] for r in sqs]
            # filter queryset by id if there are results
            if sqs:
                queryset = queryset.filter(pk__in=pks)
            else:
                queryset = queryset.none()

        # return queryset, use distinct not needed
        return queryset, False