log.error("Failed to create hanlder for object " + o.getClass().getName());
continue;
}
// Parse the object
ParsedObject parsedObject = handler.parseObject(o);
String key = parsedObject.getKey();
// if there's an existing one with the same key, then remove it first.
if (parsedObject.getKey() != null)
{
Term keyTerm = new Term(ParsedObject.FIELDNAME_KEY, key);
TopDocs topDocs = searcher.search(new TermQuery(keyTerm), 1);
if (topDocs.totalHits > 0)
{
indexWriter.deleteDocuments(keyTerm);
}
}
String type = parsedObject.getType();
String title = parsedObject.getTitle();
String description = parsedObject.getDescription();
String content = parsedObject.getContent();
String language = parsedObject.getLanguage();
URL url = parsedObject.getURL();
String className = parsedObject.getClassName();
// Create document
Document doc = new Document();
// Populate document from the parsed object
if (key != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_KEY, key, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
if (type != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_TYPE, type, Field.Store.YES, Field.Index.ANALYZED));
}
if (title != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_TITLE, title, Field.Store.YES, Field.Index.ANALYZED));
}
if (description != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_DESCRIPTION, description, Field.Store.YES, Field.Index.ANALYZED));
}
if (content != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_CONTENT, content, Field.Store.NO, Field.Index.ANALYZED));
}
if (language != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_LANGUAGE, language, Field.Store.YES, Field.Index.ANALYZED));
}
if (url != null)
{
String urlString = url.toString();
doc.add(new Field(ParsedObject.FIELDNAME_URL, urlString, Field.Store.YES, Field.Index.ANALYZED));
}
if (className != null)
{
doc.add(new Field(ParsedObject.FIELDNAME_CLASSNAME, className, Field.Store.YES, Field.Index.ANALYZED));
}
String[] keywordArray = parsedObject.getKeywords();
if(keywordArray != null)
{
for(int i=0; i<keywordArray.length; ++i)
{
String keyword = keywordArray[i];
doc.add(new Field(ParsedObject.FIELDNAME_KEYWORDS, keyword, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
}
Map keywords = parsedObject.getKeywordsMap();
addFieldsToDocument(doc, keywords, KEYWORD);
Map fields = parsedObject.getFields();
addFieldsToDocument(doc, fields, TEXT);
List<String> syntheticField = new ArrayList<String>();
for (Fieldable fieldable : doc.getFields())
{