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
Comment #1
ygerasimov commentedplease review attached patch
Comment #2
nick_vhSo 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
Comment #3
nick_vhCommited to 7.x-1.x
Comment #4
nick_vhCommitted to 6.x-3.x
Comment #5
nick_vh