in app/src/main/java/org/apache/roller/weblogger/business/search/lucene/IndexOperation.java [69:164]
protected Document getDocument(WeblogEntry data) {
// Actual comment content is indexed only if search.index.comments
// is true or absent from the (static) configuration properties.
// If false in the configuration, comments are treated as if empty.
boolean indexComments = WebloggerConfig.getBooleanProperty(
"search.index.comments", true);
String commentContent = "";
String commentEmail = "";
String commentName = "";
if (indexComments) {
List<WeblogEntryComment> comments = data.getComments();
if (comments != null) {
StringBuilder commentEmailBld = new StringBuilder();
StringBuilder commentContentBld = new StringBuilder();
StringBuilder commentNameBld = new StringBuilder();
for (WeblogEntryComment comment : comments) {
if (comment.getContent() != null) {
commentContentBld.append(comment.getContent());
commentContentBld.append(",");
}
if (comment.getEmail() != null) {
commentEmailBld.append(comment.getEmail());
commentEmailBld.append(",");
}
if (comment.getName() != null) {
commentNameBld.append(comment.getName());
commentNameBld.append(",");
}
}
commentEmail = commentEmailBld.toString();
commentContent = commentContentBld.toString();
commentName = commentNameBld.toString();
}
}
Document doc = new Document();
// keyword
doc.add(new StringField(FieldConstants.ID, data.getId(),
Field.Store.YES));
// keyword
doc.add(new StringField(FieldConstants.WEBSITE_HANDLE, data
.getWebsite().getHandle(), Field.Store.YES));
// text, don't index deleted/disabled users of a group blog
if (data.getCreator() != null) {
doc.add(new TextField(FieldConstants.USERNAME, data.getCreator()
.getUserName().toLowerCase(), Field.Store.YES));
}
// text
doc.add(new TextField(FieldConstants.TITLE, data.getTitle(),
Field.Store.YES));
// keyword needs to be in lower case as we are used in a term
doc.add(new StringField(FieldConstants.LOCALE, data.getLocale()
.toLowerCase(), Field.Store.YES));
// index the entry text, but don't store it
doc.add(new TextField(FieldConstants.CONTENT, data.getText(),
Field.Store.NO));
// keyword
doc.add(new StringField(FieldConstants.UPDATED, data.getUpdateTime()
.toString(), Field.Store.YES));
// keyword
if (data.getPubTime() != null) {
// SearchOperation sorts results by date
doc.add(new SortedDocValuesField(FieldConstants.PUBLISHED, new BytesRef(data.getPubTime().toString())));
}
// index Category, needs to be in lower case as it is used in a term
WeblogCategory categorydata = data.getCategory();
if (categorydata != null) {
doc.add(new StringField(FieldConstants.CATEGORY, categorydata
.getName().toLowerCase(), Field.Store.YES));
}
// index Comments, unstored
doc.add(new TextField(FieldConstants.C_CONTENT, commentContent,
Field.Store.NO));
// keyword
doc.add(new StringField(FieldConstants.C_EMAIL, commentEmail,
Field.Store.YES));
// keyword
doc.add(new StringField(FieldConstants.C_NAME, commentName,
Field.Store.YES));
return doc;
}