Lets say we have 100 nodes to index. But node nid 2 is changed lately (later than lets say node nid 60). Then apachesolr module after indexing node nid 2 will not index nid 60 because query that fetches nodes to index has small mistake (typo I believe):

$query = db_select($table, 'aie')
    ->fields('aie', array('entity_type', 'entity_id', 'changed'))
    ->condition('aie.status', 1)
    ->condition('aie.bundle', $bundles)
    ->condition(db_or()
      ->condition('aie.changed', $last_changed, '>')
      ->condition(db_and()
        ->condition('aie.changed', $last_changed, '=')
        ->condition('aie.entity_id', $last_entity_id, '>')))
    ->orderBy('aie.entity_id', 'ASC');

Comments

ygerasimov’s picture

Status: Active » Needs review
StatusFileSize
new966 bytes

please review attached patch

nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

So let's review
$last_changed = 105
items per cron = 2

5 nodes
id timestamp
1 100
2 140 (this is our exception)
3 110
4 130
5 120

(first set so we try indexing two items)
SELECT aie.entity_type AS entity_type, aie.entity_id AS entity_id, aie.changed AS changed
FROM
{apachesolr_index_entities_node} aie
WHERE (aie.status = '1')
AND (aie.bundle IN ('article', 'page'))
AND( (aie.changed > '50') OR ((aie.changed = '50') AND (aie.entity_id > '0')) )
ORDER BY aie.entity_id ASC
LIMIT 50 OFFSET 0

This will retrieve 1, 2
$last_changed = $last_row = 140 and $last_id = 2

SELECT aie.entity_type AS entity_type, aie.entity_id AS entity_id, aie.changed AS changed
FROM
{apachesolr_index_entities_node} aie
WHERE (aie.status = '1')
AND (aie.bundle IN ('article', 'page'))
AND( (aie.changed > '140') OR ((aie.changed = '140') AND (aie.entity_id > '2')) )
ORDER BY aie.entity_id ASC
LIMIT 50 OFFSET 0

This will retrieve nothing (Error reproduced)
$last_changed = $last_row = 140 and $last_id = 2

Suggestion :
SELECT aie.entity_type AS entity_type, aie.entity_id AS entity_id, aie.changed AS changed
FROM
{apachesolr_index_entities_node} aie
WHERE (aie.status = '1')
AND (aie.bundle IN ('article', 'page'))
AND( (aie.changed > '140') OR ((aie.changed <= '140') AND (aie.entity_id > '2')) )
ORDER BY aie.entity_id ASC
LIMIT 50 OFFSET 0

This will retrieve 3, 4
$last_changed = $last_row = 130 and $last_id = 4

Good catch

nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Commited to 7.x-1.x

nick_vh’s picture

Status: Patch (to be ported) » Fixed

Committed to 6.x-3.x

nick_vh’s picture

Status: Fixed » Closed (fixed)