doc.add(new Field("url", url, Field.Store.YES, Field.Index.NOT_ANALYZED));
// Add the file name (without protocol, drive-letter and path)
String filenameWithVariants = RegainToolkit.urlToWhitespacedFileName(url);
doc.add(new Field("filename", new WhitespaceTokenizer(new StringReader(filenameWithVariants))));
PathFilenamePair pfPair = RegainToolkit.fragmentUrl(url);
// Add the filename field for sorting
doc.add(new Field("filename_sort", pfPair.getFilename(), Field.Store.YES, Field.Index.NOT_ANALYZED));
// Add the document's size
int size = rawDocument.getLength();
doc.add(new Field("size", Integer.toString(size), Field.Store.YES, Field.Index.NOT_ANALYZED));
// Add the mime-type
String mimeType = rawDocument.getMimeType();
doc.add(new Field("mimetype", mimeType, Field.Store.YES, Field.Index.NOT_ANALYZED));
// Add last modified
Date lastModified = rawDocument.getLastModified();
if (lastModified == null) {
// We don't know when the document was last modified
// -> Take the current time
lastModified = new Date();
}
doc.add(new Field("last-modified",
DateTools.dateToString(lastModified, DateTools.Resolution.DAY), Field.Store.YES,
Field.Index.NOT_ANALYZED));
// Write the raw content to an analysis file
writeContentAnalysisFile(rawDocument);
// Add the additional fields
if (additionalFieldMap != null) {
Iterator iter = additionalFieldMap.keySet().iterator();
while (iter.hasNext()) {
String fieldName = (String) iter.next();
String fieldValue = (String) additionalFieldMap.get(fieldName);
//doc.add(new Field(fieldName, fieldValue, Field.Store.COMPRESS, Field.Index.ANALYZED));
doc.add(new Field(fieldName, fieldValue, Field.Store.NO, Field.Index.ANALYZED));
doc.add(new Field(fieldName, CompressionTools.compressString(fieldValue), Field.Store.YES));
}
}
if (hasContent(cleanedContent)) {
// Write the clean content to an analysis file
writeAnalysisFile(url, "clean", cleanedContent);
// Add the cleaned content of the document
doc.add(new Field("content", cleanedContent,
this.storeContentForPreview ? Field.Store.YES : Field.Store.NO, Field.Index.ANALYZED));
} else {
// We have no content! This is a substitute document
// -> Add a "preparation-error"-field
doc.add(new Field("preparation-error", "true", Field.Store.YES,
Field.Index.NO));
}
// Check whether to use the link text as title
for (int i = 0; i < mUseLinkTextAsTitleReArr.length; i++) {
if (mUseLinkTextAsTitleReArr[i].match(url)) {
String linkText = rawDocument.getSourceLinkText();
if (linkText != null) {
title = linkText;
}
break;
}
}
// Add the document's title
if (hasContent(title)) {
doc.add(new Field("title", title, Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("title_sort", title.toLowerCase(), Field.Store.YES, Field.Index.NOT_ANALYZED));
} else {
doc.add(new Field("title_sort", "", Field.Store.YES, Field.Index.NOT_ANALYZED));
}
// Add the document's summary
if (! hasContent(summary) && hasContent(cleanedContent)) {
summary = createSummaryFromContent(cleanedContent);
}
if (hasContent(summary)) {
doc.add(new Field("summary", summary, Field.Store.NO, Field.Index.ANALYZED));
doc.add(new Field("summary", CompressionTools.compressString(summary), Field.Store.YES));
}
// Add the document's metadata
if (hasContent(metadata)) {
doc.add(new Field("metadata", metadata, Field.Store.YES, Field.Index.ANALYZED));
}
// Add the document's headlines
if (hasContent(headlines)) {
doc.add(new Field("headlines", headlines, Field.Store.NO,
Field.Index.ANALYZED));
}
// Add the document's path
if (pfPair.getPath() != null) {
//String asString = pathToString(path);
doc.add(new Field("path", pfPair.getPath(), Field.Store.YES, Field.Index.NO));
doc.add(new Field("path_sort", pfPair.getPath().toLowerCase(), Field.Store.YES, Field.Index.NOT_ANALYZED));
// Write the path to an analysis file
writeAnalysisFile(url, "path", pfPair.getPath());
} else {
doc.add(new Field("path_sort", "", Field.Store.YES, Field.Index.NOT_ANALYZED));
}
return doc;