Solr: Determine if a document exists

I am a SolrJ beginner and want to find out whats the fastest way to determine if an document with an unique ID exists? I don't need the document, I just want to find out if it is already in the index.

Now I try something like this in SolrJ:

private boolean solrContainsId(final String id) {
    SolrQuery query = new SolrQuery("id:" + id);

    try {
        long count = server.query(query).getResults().getNumFound();
        return count > 0;
    } catch (SolrServerException e) {
        return false;
    }
}

I think there will be better (faster?) ways which don't need scoring etc. ...

Answer:1

I have a Validator interface which provides a isValid(Thing) method, returning a ValidationResult which contains a boolean and a reason message. I want to create a ValidatorAggregator implementation ...

I'm stuck. Coming from C++ I thought this would simply work, but it does not. Can you please give me an advice? I will try to not end up with kind of creation method in each class used for T. public ...

Is there a way to set a button key event in Java so that Alt does not have to be pressed. For example, when this is used setMnemonic(KeyEvent.VK_DELETE) it is required for Alt + Delete to be pressed ...

Below is a code snippet of ArrayList, which either takes in the 'initialCapacity' provided by the user or default of 10. My question - why was 10 not a static constant ? I guess constants are used ...