package com.qmth.qrzk.web.listener;

import java.util.List;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

import com.qmth.qrzk.repository.user.model.Question;

public class DocumentsUtil {

	public static void Question2Document(List<Question> list,List<Document> documents){
		for(int i=0;i<list.size();i++){
			Question q=list.get(i);
			Document document =new Document();
			document.add(new Field("id",String.valueOf(q.getId()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			
			if(q.getQuestionNo()==null)
				q.setQuestionNo("");
			document.add(new Field("questionNo",q.getQuestionNo(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("courseId",String.valueOf(q.getCourseId()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("courseName",String.valueOf(q.getCourseName()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("typeId",String.valueOf(q.getTypeId()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("typeName",String.valueOf(q.getTypeName()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("bookId",String.valueOf(q.getBookId()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("bookName",String.valueOf(q.getBookName()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("batchId",String.valueOf(q.getBatchId()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getEstimateDifficultyCode()==null)
				q.setEstimateDifficultyCode("");
			document.add(new Field("estimateDifficultyCode",q.getEstimateDifficultyCode(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getMeasuredDifficultyCode()==null)
				q.setMeasuredDifficultyCode("");
			document.add(new Field("measuredDifficultyCode",q.getMeasuredDifficultyCode(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getGradeCode()==null)
				q.setGradeCode("");
			document.add(new Field("gradeCode",q.getGradeCode(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getAbilityCode()==null)
				q.setAbilityCode("");
			document.add(new Field("abilityCode",q.getAbilityCode(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getChapter()==null)
				q.setChapter("");
			document.add(new Field("chapter",q.getChapter(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getSection()==null)
				q.setSection("");
			document.add(new Field("section",q.getSection(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getItem()==null)
				q.setItem("");
			document.add(new Field("item",q.getItem(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getPage()==null)
				q.setPage("");
			document.add(new Field("page",q.getPage(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("score",String.valueOf(q.getScore()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getBodyWord()==null)
				q.setBodyWord("".getBytes());
			document.add(new Field("bodyWord",q.getBodyWord(),Field.Store.YES));
			if(q.getBody()==null)
				q.setBody("");
			document.add(new Field("body",q.getBody(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getBodySummary()==null)
				q.setBodySummary("");
			document.add(new Field("bodySummary",q.getBodySummary(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getAnswerWord()==null)
				q.setAnswerWord("".getBytes());
			document.add(new Field("answerWord",q.getAnswerWord(),Field.Store.YES));
			if(q.getAnswer()==null)
				q.setAnswer("");
			document.add(new Field("answer",q.getAnswer(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getAnswerSummary()==null)
				q.setAnswerSummary("");
			document.add(new Field("answerSummary",q.getAnswerSummary(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getAnswerSheet()==null)
				q.setAnswerSheet("");
			document.add(new Field("answerSheet",q.getAnswerSheet(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getStatusCode()==null)
				q.setStatusCode("");
			document.add(new Field("statusCode",q.getStatusCode(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("setBy",String.valueOf(q.getSetBy()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getSetTeacherName()==null)
				q.setSetTeacherName("");
			document.add(new Field("setTeacherName",q.getSetTeacherName(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			if(q.getRemark()==null)
				q.setRemark("");
			document.add(new Field("remark",q.getRemark(),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("createdBy",String.valueOf(q.getCreatedBy()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			document.add(new Field("assessmentDemand",String.valueOf(q.getAssessmentDemand()),Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
			documents.add(document);
		}
	}
}
