public void indexDocument(int docId, Predicate predicate) {
        if (documentIdCounter == Integer.MAX_VALUE) {
            throw new IllegalStateException("Index is full, max number of documents is: " + Integer.MAX_VALUE);
        } else if (seenIds.contains(docId)) {
            throw new IllegalArgumentException("Document id is already in use: " + docId);
        } else if (isNeverMatchingDocument(predicate)) {
            return;
        }
        seenIds.add(docId);
        predicate = optimizer.optimizePredicate(predicate);
        int internalId = documentIdCounter++;
        if (isAlwaysMatchingDocument(predicate)) {
            indexZeroConstraintDocument(internalId);
        } else {
            indexDocument(internalId, PredicateTreeAnnotator.createPredicateTreeAnnotations(predicate));
        }
    }
Indexes a predicate with the given id.

@param docId     a 32-bit document id, returned in the Hit objects when the predicate matches
@param predicate the predicate to index
predicate-search/src/main/java/com/yahoo/search/predicate/PredicateIndexBuilder.java