Hi Aron,
I'd like this feature too. It is not currently available in Solrpy, but I'd be happy to implement it -- at least in a solrpy fork -- if:
- we can be assured that the 4.0-BETA interfaces are stable enough.
- we can agree on how we would like it to look from a Python perspective.
On the first point:
The feature is at present poorly documented. At the moment, Solrpy only supports update, etc. instructions in XML, for which the syntax is like:
<field name="price" update="set">300</field>
I'm not really a big fan of this syntax, or the JSON, because it makes things very verbose if you want to add a single field to thousands of documents. I also don't understand why the distinction between an 'insert' and 'update' operation is made implicitly by providing information on fields.
I also don't like the JSON syntax because it would appear in [{"id":"1","price":{"set":100}}]
As if you could simultaneously set, add and inc a field by writing [{"id":"1","price":{"set":100, "add":10, "inc": 1}}]. Nonsense! Semantically, we're trying to say [{"id":"1","price":{"op": "set", "val": 100}}], but that's also horrendously verbose.
On the second point:
Obviously, conn.add(id=1, price=100) doesn't provide sufficient information for solrpy to send this as a 'set' operation. There are a few ways we could make this look:
- conn.add(id=1, price__set=100)
- conn.add(id=1, price={'set': 100})
- conn.add(id=1, __set={price: 100})
- conn.updater(price='set').add(id=1, price=100)
The first is Django-inspired, and so will be familiar to many Python devs. The second is close to the JSON syntax, meaning that if solrpy moves to JSON update requests, it'll be trivial to pass it on to the server. The third has the advantage of being succinct when there are multiple fields being updated, because you can say __set={price: 100, name: "Better name", description: "Better description"}, etc.
The last is my favourite as a programmatic interface, because it is clear semantically and robust to a change in the Solr syntax, especially if better accommodating batch updates.
Thoughts?
Cheers,
- Joel