Refactor Indexing Operations
So the indexing class and associated operations are getting messy inside, and the external API syntax is starting to become unwieldy. Most of the problems stem from batch processing - the syntax was originally designed for single-document operations. The addition of batches (and streaming batches) has complicated the single-document metaphor and things are kinda gross now.
I'd like to give the whole indexing syntax an overhaul. I'm leaning towards a syntax that has this basic structure:
$doc = $sherlock->document()
->index('testindexing')->type('tweet')
->document(array("field" => "test"))
->insert();
$response = $doc->execute();
This would allow configuring each individual document much easier, while still playing nicely with batch. In particular, it would allow mixing operations like this:
$doc = $sherlock->document()
->index('testindexing')->type('tweet')
->document(array("field" => "test"))
->insert();
->index('differentIndex')->type('message')
->document(array("field" => "test"))
->id(123)
->insert();
->index('differentIndex')->type('message')
->document(array("field" => "test"))
->update();
->index('differentIndex')->type('message')
->updateScript('sample script')
->updateParams($params)
->update();
->index('testindexing')->type('tweet')
->id(123)
->delete();
->index('testindexing')->type('tweet')
->id(456)
->get();
$response = $doc->execute();
Basically, Sherlock->document() becomes a collection of entirely independent Commands which all operate at the document level. This is essentially how the code is structured already, but since it was built single-documents and then extended to batch, the outward facing interface is clunky.
Thoughts?
Sounds good.
Here's something completely different, not sure if it fits any standards or not. Just some wild suggestion to bring in another perspective. In this example you only need to select your index and type once, and on that index you specify your command and within that command you can create a batch of actions to perform.
$doc = $sherlock
->index('testindexing')
->type('tweet')
->insert()
->document(array("field" => "test"));
->document(array("field" => "test2"));
->document(array("field" => "test3"));
->type('message')
->delete()
->id(123)
->id(789)
->id({999, 1000, 1001});
->get()
->id(456);
->index('differentIndex')->type('message')
->insert()
->document(array("field" => "test"))
->id(123, 789);
->document(array("field" => "test2"))
->id("string_456");
->update();
->document(array("field" => "test3"))
->id(123);
->update()
->updateScript('sample script')
->updateParams($params);
in my current implementation I used a string as document ID, because the ID's of my entities are not universal unique, but only within their table, thus i need a prefix for my document ID.