예제 #1
0
    def index_doc(self, docid, texts):
        texts = ISearchableContent(texts, None)
        if texts is None:
            return

        if self.optimize_index:
            request = getRequest()
            if request is not None and \
                    getattr(request, 'publication', None) is not None:
                localData.add(self, docid, texts)
                return

        self._index_doc(docid, texts)
예제 #2
0
    def searchResults(self, sort_on=None, sort_order=None, searchContext=None,
                      noPublishing=False, noSecurityChecks=False,
                      showHidden=False, indexes=None,
                      _max_expires=datetime(2199, 1, 1, tzinfo=utc),
                      _min_effective=datetime(1999, 12, 31, tzinfo=utc),
                      **searchterms):

        # publishing info
        if not noPublishing:
            tz = ITZInfo(getRequest(), utc)
            value = datetime.now(tz)
            now = datetime(
                value.year, value.month, value.day, value.hour,
                value.minute, value.second, value.microsecond, tz)

            if 'expires' not in searchterms:
                searchterms['expires'] = {'between': (now, _max_expires)}
            if 'effective' not in searchterms:
                searchterms['effective'] = {'between': (_min_effective, now)}

        # security info
        if not noSecurityChecks:
            request = getRequest()
            if request is not None:
                if searchContext is not None:
                    users = listAllowedRoles(request.principal, searchContext)
                else:
                    users = listAllowedRoles(request.principal, getSite())

                searchterms['allowedRoleAndPrincipals'] = {'any_of': users}

        # hidden
        if 'hidden' not in searchterms:
            if showHidden:
                searchterms['hidden'] = {'any_of': (True, False)}
            else:
                searchterms['hidden'] = {'any_of': (False,)}

        # search context
        if searchContext is None:
            searchContext = getSite()

        if isinstance(searchContext, dict):
            searchterms['searchContext'] = searchContext
        else:
            context = getSearchContext(searchContext, False)
            if context:
                searchterms['searchContext'] = {'any_of': context}

        #apply pluggable query
        searchterms.update(self.getPluggableQuery())

        # apply
        results = self.apply(searchterms, sort_on, indexes)

        if results is None:
            results = IFBTree()

        uidutil = getUtility(IIntIds)
        if sort_order == 'reverse':
            return ReverseResultSet(results, uidutil)
        else:
            return ResultSet(results, uidutil)