*/
public void put(Document d) throws ThrudexException, TException {
//make sure index is valid
if(!isValidIndex(d.index))
throw new ThrudexExceptionImpl("No Index Found: "+d.index);
//make sure document has a key
if(!d.isSetKey() || d.key.trim().equals(""))
throw new ThrudexExceptionImpl("No Document key found");
//Start new lucene document
org.apache.lucene.document.Document luceneDocument =
new org.apache.lucene.document.Document();
luceneDocument.add(
new org.apache.lucene.document.Field(
LuceneIndex.DOCUMENT_KEY,d.key,
org.apache.lucene.document.Field.Store.YES,
org.apache.lucene.document.Field.Index.NOT_ANALYZED
)
);
//Add fields
for(Field field : d.fields){
if(!field.isSetKey())
throw new ThrudexExceptionImpl("Field key not set");
if(!field.isSetType())
throw new ThrudexExceptionImpl("FieldType missing");
//Convert FieldType to Lucene types
org.apache.lucene.document.Field.Store fieldStoreType;
org.apache.lucene.document.Field.Index fieldIndexType;
switch(field.type){
case FieldType.TEXT:
fieldStoreType = org.apache.lucene.document.Field.Store.YES;
fieldIndexType = org.apache.lucene.document.Field.Index.ANALYZED;
break;
case FieldType.UNSTORED:
fieldStoreType = org.apache.lucene.document.Field.Store.NO;
fieldIndexType = org.apache.lucene.document.Field.Index.ANALYZED;
break;
case FieldType.KEYWORD:
fieldStoreType = org.apache.lucene.document.Field.Store.YES;
fieldIndexType = org.apache.lucene.document.Field.Index.NOT_ANALYZED;
break;
default:
throw new ThrudexExceptionImpl("Unknown FieldType: "+field.type);
}
//Create Lucene Field
org.apache.lucene.document.Field luceneField =
new org.apache.lucene.document.Field(field.key, field.value, fieldStoreType,fieldIndexType);