diff --git a/docs/topics/request-response.rst b/docs/topics/request-response.rst index baeec8701..089c8bcd5 100644 --- a/docs/topics/request-response.rst +++ b/docs/topics/request-response.rst @@ -77,11 +77,10 @@ Request objects body to ``str`` (if given as ``unicode``). :type encoding: string - :param priority: the priority of this request (defaults to ``0.0``). - The priority is used by the scheduler to define the order used to return - requests. It can also be used to feed priorities externally, for - example, using an offline long-term scheduler. - :type encoding: int or float + :param priority: the priority of this request (defaults to ``0``). + The priority is used by the scheduler to define the order used to process + requests. + :type priority: int :param dont_filter: indicates that this request should not be filtered by the scheduler. This is used when you want to perform an identical diff --git a/docs/topics/settings.rst b/docs/topics/settings.rst index b218ba8f4..61f1d0b21 100644 --- a/docs/topics/settings.rst +++ b/docs/topics/settings.rst @@ -338,7 +338,7 @@ DEPTH_PRIORITY Default: ``1`` -An integer that is used to set the request priority based on request depth. +An integer that is used to adjust the request priority based on its depth. To crawl in `breadth-first order`_, set :setting:`DEPTH_PRIORITY` to ``1``. diff --git a/scrapy/contrib/spidermiddleware/depth.py b/scrapy/contrib/spidermiddleware/depth.py index 978e7baef..20390280e 100644 --- a/scrapy/contrib/spidermiddleware/depth.py +++ b/scrapy/contrib/spidermiddleware/depth.py @@ -47,7 +47,7 @@ class DepthMiddleware(object): depth = response.request.meta['depth'] + 1 request.meta['depth'] = depth if self.prio: - request.priority += depth * self.prio + request.priority -= depth * self.prio if self.maxdepth and depth > self.maxdepth: log.msg("Ignoring link (depth > %d): %s " % (self.maxdepth, request.url), \ level=log.DEBUG, spider=spider) diff --git a/scrapy/core/scheduler.py b/scrapy/core/scheduler.py index f6f414411..ba3dccc4e 100644 --- a/scrapy/core/scheduler.py +++ b/scrapy/core/scheduler.py @@ -58,7 +58,7 @@ class Scheduler(object): return try: reqd = request_to_dict(request, self.spider) - self.dqs.push(reqd, request.priority) + self.dqs.push(reqd, -request.priority) except ValueError: # non serializable request return else: @@ -67,7 +67,7 @@ class Scheduler(object): def _mqpush(self, request): stats.inc_value('scheduler/memory_enqueued', spider=self.spider) - self.mqs.push(request, request.priority) + self.mqs.push(request, -request.priority) def _dqpop(self): if self.dqs: