public final void writeDocList(String name, DocList ids, Set<String> fields)
			throws IOException {
	
		boolean includeScore = false;
		if (fields != null) {
			includeScore = fields.contains("score");
			if (fields.size() == 0 || (fields.size() == 1 && includeScore)
					|| fields.contains("*")) {
				fields = null; // null means return all stored fields
			}
		}

		int sz = ids.size();

		writer.write("<result");
		writeAttr("name", name);
		writeAttr("numFound", Integer.toString(ids.matches()));
		writeAttr("start", Integer.toString(ids.offset()));
		if (includeScore) {
			writeAttr("maxScore", Float.toString(ids.maxScore()));
		}
		if (sz == 0) {
			writer.write("/>");
			return;
		} else {
			writer.write('>');
		}

		DocIterator iterator = ids.iterator();
		for (int i = 0; i < sz; i++) {
			int id = iterator.nextDoc();
			Document doc = searcher.doc(id, fields);
			writeDoc(null, doc, fields, (includeScore ? iterator.score() : 0.0f), includeScore, id);
			
		}

		writer.write("</result>");
		cleanUp();
	}