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)
{
SolrQuery query = new SolrQuery();
String queryString = new StringBuilder(40).append(ParsedObject.FIELDNAME_KEY).append(':').append(ClientUtils.escapeQueryChars(key)).toString();
query.setQuery(queryString);
QueryResponse qrsp = server.query(query);
if (!qrsp.getResults().isEmpty())
{
UpdateResponse ursp = server.deleteByQuery(queryString);
if (ursp.getStatus() < 300)
{
server.commit();
}
}
}
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
SolrInputDocument doc = new SolrInputDocument();
// Populate document from the parsed object
if (key != null)
{
doc.addField(ParsedObject.FIELDNAME_KEY, key, 1.0f);
}
if (type != null)
{
doc.addField(ParsedObject.FIELDNAME_TYPE, type, 1.0f);
}
if (title != null)
{
doc.addField(ParsedObject.FIELDNAME_TITLE, title, 1.0f);
}
if (description != null)
{
doc.addField(ParsedObject.FIELDNAME_DESCRIPTION, description, 1.0f);
}
if (content != null)
{
doc.addField(ParsedObject.FIELDNAME_CONTENT, content, 1.0f);
}
if (language != null)
{
doc.addField(ParsedObject.FIELDNAME_LANGUAGE, language, 1.0f);
}
if (url != null)
{
String urlString = url.toString();
doc.addField(ParsedObject.FIELDNAME_URL, urlString, 1.0f);
}
if (className != null)
{
doc.addField(ParsedObject.FIELDNAME_CLASSNAME, className, 1.0f);
}
String[] keywordArray = parsedObject.getKeywords();
if(keywordArray != null)
{
for(int i=0; i<keywordArray.length; ++i)
{
String keyword = keywordArray[i];
doc.addField(ParsedObject.FIELDNAME_KEYWORDS, keyword, 1.0f);
}
}
Map keywords = parsedObject.getKeywordsMap();
addFieldsToDocument(doc, keywords);
Map fields = parsedObject.getFields();
addFieldsToDocument(doc, fields);
List<String> syntheticField = new ArrayList<String>();
for (Map.Entry<String, SolrInputField> entry : doc.entrySet())
{