Reuben Firmin wrote:
Is it expected behaviour that "deleteById" will always return OK as a
status, regardless of whether the id was matched?

It is expected behaviour as Solr always returns 0 unless an error occurs
during processing a request (query, update, ...), so you don't need to check
the status, but you'll get an exception if something wrong; otherwise
the request succeeded.

And you cannot know whether the id was matched. The only way
you can try is send a query "q=id:value&rows=0" and check the numFound
in the response before sending deleteById.

Koji

I have a unit test:

          // set up the test data
engine.index(12345, s1, d1);
engine.index(54321, s2, d2);
engine.index(23453, s3, d3);

// ...

    @Test
    public void testRemove() throws Exception {
        assertEquals(engine.size(), 3);
        assertTrue(engine.remove(12345));
        assertEquals(engine.size(), 2);
        // XXX, it returns true
        assertFalse(engine.remove(23523352));

"Engine" is my wrapper around Solr. The remove method looks like this:

private static final int RESPONSE_STATUS_OK = 0;
private SolrServer server;

    public boolean remove(final Integer titleInstanceId)
    throws IOException
    {
        try {
            server.deleteById(String.valueOf(titleInstanceId));
            final UpdateResponse updateResponse = server.commit(true, true);
            // XXX It's always OK
            return (updateResponse.getStatus() == RESPONSE_STATUS_OK);

Any ideas what's going wrong? Is there a different way to test for the id
not having been there, other than an additional search?

Thanks
Reuben


Reply via email to