pankajit / solr-php-client

Automatically exported from code.google.com/p/solr-php-client
Other
0 stars 1 forks source link

Add a method to delete multiple documents by ID #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently there is no method in the client that supports deleting a list of
documents by ID.  One would have to construct a large OR query and pass it
to the method to delete by query. Solr supports delete documents with
multiple ID elements, which shoudl have a little better performance than
the mass query.

I am adding such a method here for our subclassed Solr client for the
Drupal module http://drupal.org/node/561082#comment-2147374

relevant code:
<code>
+  /**
+   * Create and post a delete document based on multiple document IDs.
+   *
+   * @param array $ids Expected to be utf-8 encoded strings
+   * @return Apache_Solr_Response
+   *
+   * @throws Exception If an error occurs during the service call
+   */
+  public function deleteMultipleById($ids) {
+    $rawPost = "<delete>\n";
+    foreach ($ids as $id) {
+      // Escape special xml characters
+      $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
+      $rawPost .= '<id>' . $id . "</id>\n";
+    }
+    $rawPost .= '</delete>';
+    return $this->delete($rawPost);
+  }
</code>

Original issue reported on code.google.com by pwola...@gmail.com on 14 Oct 2009 at 2:01

GoogleCodeExporter commented 9 years ago
Sounds like a necessary addition, thank you for bringing it up. Any objection 
to me calling it deleteByIds instead? 
The reason I suggest this is that it would make it show up along side the 
current deleteById method instead of 
after deleteByQuery  when using IDE code tools.  

Original comment by donovan....@gmail.com on 19 Oct 2009 at 4:44

GoogleCodeExporter commented 9 years ago
how about something like deleteByMultipleIds() or deleteByIdMultiple()?

I think the Id to Ids difference will not be very obvious when reading code.

Original comment by pwola...@gmail.com on 21 Oct 2009 at 4:18

GoogleCodeExporter commented 9 years ago
Added method deleteByMultipleIds in r20

Original comment by donovan....@gmail.com on 9 Nov 2009 at 9:33