private SolrInputDocument indexEntityState( final EntityState entityState,
final SolrServer server )
throws IOException, SolrServerException, JSONException
{
Graph graph = new GraphImpl();
stateSerializer.serialize( entityState, false, graph );
SolrInputDocument input = new SolrInputDocument();
input.addField( "id", entityState.identity().identity() );
input.addField( "type", first(entityState.entityDescriptor().types()).getName() );
input.addField( "lastModified", new Date( entityState.lastModified() ) );
for( Statement statement : graph )
{
SchemaField field = indexedFields.get( statement.getPredicate().getLocalName() );
if( field != null )
{
if( statement.getObject() instanceof Literal )
{
String value = statement.getObject().stringValue();
if( field.getType().getTypeName().equals( "json" ) )
{
if( value.charAt( 0 ) == '[' )
{
JSONArray array = new JSONArray( value );
indexJson( input, array );
} else if( value.charAt( 0 ) == '{' )
{
JSONObject object = new JSONObject( value );
indexJson( input, object );
}
} else
{
input.addField( field.getName(), value );
}
} else if( statement.getObject() instanceof URI && !"type".equals( field.getName() ) )
{
String value = statement.getObject().stringValue();
value = value.substring( value.lastIndexOf( ':' ) + 1, value.length() );
String name = field.getName();
input.addField( name, value );
} else if( statement.getObject() instanceof BNode )
{
Iterator<Statement> seq = graph.match( (Resource) statement.getObject(), new URIImpl( "http://www.w3.org/1999/02/22-rdf-syntax-ns#li" ), null, (Resource) null );
while( seq.hasNext() )
{
Statement seqStatement = seq.next();
String value = seqStatement.getObject().stringValue();
value = value.substring( value.lastIndexOf( ':' ) + 1, value.length() );