static void indexDocs(IndexWriter writer, File file)
			throws IOException {
		// do not try to index files that cannot be read
		if (file.canRead()) {
			if (file.isDirectory()) {
				String[] files = file.list();
				// an IO error could occur
				if (files != null) {
					for (int i = 0; i < files.length; i++) {
						indexDocs(writer, new File(file, files[i]));
					}
				}
			} else {
				TrecDocIterator docs = new TrecDocIterator(file);
				Document doc;
				while (docs.hasNext()) {
					doc = docs.next();
					if (doc != null && doc.getField("contents") != null)
						writer.addDocument(doc);
				}
			}
		}
	}