title: magento - reindex category product position
body: <p>I've developed a custom product sort module with drag'n'drop and, for simplicity and speeds sake, it updates directly to the EAV tables.  I save this new position with:</p>
  
  <pre><code>$write = Mage::getSingleton('core/resource')-&gt;getConnection('core_write');
  $write-&gt;beginTransaction();
  
  for ($i = 0; $i &lt; sizeof($ids); $i++)
  {
      $query = "UPDATE catalog_category_product SET position='".$i."' WHERE product_id='".$ids[$i]."' AND category_id='".$cat."'";
      $write-&gt;query($query);
  }
  
  $write-&gt;commit();
  </code></pre>
  
  <p>My question is how I can force a reindex on only the affected changes so that the position sorting is visible in the frontend.</p>
  
  <p>I've tried to dispatch several different events like for example this:</p>
  
  <pre><code>Mage::dispatchEvent('catalog_product_flat_rebuild', array(
      'store_id' =&gt; Mage::app()-&gt;getStore()-&gt;getStoreId(),
      'table'    =&gt; Mage::getResourceSingleton('catalog/category_flat')-&gt;getMainStoreTable(Mage::app()-&gt;getStore()-&gt;getStoreId())
  ));
  </code></pre>
  
  <p>But I still see the old sort order in the frontend, and also this would reindex the full flat table, I would prefer to just reindex the array of Product ID's  and category ID that I changed position on.  Any ideas on how I would accomplish this?</p>
  
  <p>Thanks in advance!</p>