1. Juan Carlos Picado Herrera
  2. encuestame

Commits

Juan Carlos Picado Herrera  committed e18538a Merge

Merge branch 'release'

  • Participants
  • Parent commits 1ecbd31, a1d019a
  • Branches master

Comments (0)

Files changed (53)

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractChartService.java

View file
  • Ignore whitespace
  * @version $Id:$
  */
 @Service
-public abstract class AbstractChartService extends AbstractBaseService {
+public abstract class AbstractChartService extends AbstractIndexService {
 
 }

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractIndexService.java

View file
  • Ignore whitespace
+
+package org.encuestame.business.service;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.encuestame.core.util.ConvertDomainBean;
+import org.encuestame.persistence.domain.HashTag;
+import org.encuestame.persistence.domain.Question;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.web.HashTagBean;
+import org.encuestame.utils.web.QuestionBean;
+
+/**
+ * Provide of index/search layer.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 18, 2011
+ */
+public abstract class AbstractIndexService extends AbstractBaseService{
+
+    /**
+     * Log.
+     */
+    private Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * List Suggested Hash Tags.
+     * @param hashTagKeyWord keyword to search
+     * @param maxResults limit of results
+     * @return list of hash tags.
+     */
+    public List<HashTagBean> listSuggestHashTags(final String hashTagKeyWord, final Integer maxResults){
+        final List<HashTag> tags = getHashTagDao().getListHashTagsByKeyword(hashTagKeyWord, maxResults);
+        log.debug("Hash Tag Suggested size "+tags.size());
+        return ConvertDomainBean.convertListHashTagsToBean(tags);
+    }
+
+    /**
+     * Return suggested list of questions by keyword on indexed results.
+     * @param keyword keyword to search
+     * @param username username logged
+     * @return
+     * @throws EnMeNoResultsFoundException
+     */
+    public List<QuestionBean> searchIndexedQuestions(final String keyword, final String username)
+           throws EnMeNoResultsFoundException{
+        final List<Question> questions = getQuestionDao().retrieveIndexQuestionsByKeyword(keyword,
+                                         getUserAccount(username).getAccount().getUid());
+        return ConvertDomainBean.convertListToUnitQuestionBean(questions);
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractSurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.utils.web.UnitAnswersBean;
-import org.encuestame.utils.web.UnitHashTag;
+import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitTweetPoll;
 import org.encuestame.utils.web.UnitTweetPollResult;
 import org.hibernate.HibernateException;
 
     /**
      * Create Question.
-     * @param questionBean {@link UnitQuestionBean}.
+     * @param questionBean {@link QuestionBean}.
      * @throws EnMeExpcetion exception
      */
-    public Question createQuestion(final UnitQuestionBean questionBean) throws EnMeExpcetion{
+    public Question createQuestion(final QuestionBean questionBean) throws EnMeExpcetion{
               final Question question = new Question();
             try{
 
      * @return
      * @throws EnMeExpcetion exception.
      */
-    public HashTag createHashTag(final UnitHashTag unitHashTag) throws EnMeExpcetion{
+    public HashTag createHashTag(final HashTagBean unitHashTag) throws EnMeExpcetion{
         try{
             final HashTag tag = new HashTag();
             tag.setHashTag(unitHashTag.getHashTagName());
 
     /**
      * Load all questions.
-     * @return List of {@link UnitQuestionBean}
+     * @return List of {@link QuestionBean}
      * @throws EnMeExpcetion exception
      */
-    public List<UnitQuestionBean> loadAllQuestions() throws EnMeExpcetion {
-        final List<UnitQuestionBean> listQuestionBean = new LinkedList<UnitQuestionBean>();
+    public List<QuestionBean> loadAllQuestions() throws EnMeExpcetion {
+        final List<QuestionBean> listQuestionBean = new LinkedList<QuestionBean>();
         try {
             final  List<Question> questionsList = getQuestionDao()
                     .loadAllQuestions();
             if (questionsList.size() > 0) {
 
                for (Question questions : questionsList) {
-                    final UnitQuestionBean q = new UnitQuestionBean();
+                    final QuestionBean q = new QuestionBean();
                     q.setId(Long.valueOf(questions.getQid().toString()));
                     q.setQuestionName(questions.getQuestion());
                     listQuestionBean.add(q);
      * @return unitQuestionBean
      * @throws EnMeNoResultsFoundException
      */
-    public List<UnitQuestionBean> listSuggestQuestion(final String questionKeyword, final String username) throws EnMeNoResultsFoundException{
-        final List<UnitQuestionBean> unitQuestionBean = new ArrayList<UnitQuestionBean>();
+    public List<QuestionBean> listSuggestQuestion(final String questionKeyword, final String username) throws EnMeNoResultsFoundException{
+        final List<QuestionBean> unitQuestionBean = new ArrayList<QuestionBean>();
         final List<Question> questionsList = getQuestionDao().retrieveIndexQuestionsByKeyword(questionKeyword, getPrimaryUser(username));
         log.info("listSuggestQuestion "+questionsList.size());
         for (Question question : questionsList) {
     }
 
     /**
-     * List Suggested Hash Tags.
-     * @param hashTagKeyWord
-     * @param maxResults
-     * @return
-     */
-    public List<UnitHashTag> listSuggestHashTags(final String hashTagKeyWord, final Integer maxResults){
-        final List<HashTag> tags = getHashTagDao().getListHashTagsByKeyword(hashTagKeyWord, maxResults);
-        log.debug("Hash Tag Suggested size "+tags.size());
-        return ConvertDomainBean.convertListHashTagsToBean(tags);
-    }
-
-    /**
      * Validate TweetPoll IP.
      * @param ipVote  ipVote
      * @param tweetPoll tweetPoll
      * @param unitQuestionPoll
      * @throws EnMeExpcetion  Exception
      */
-     public void updateQuestion(final UnitQuestionBean unitQuestionPoll) throws EnMeExpcetion{
+     public void updateQuestion(final QuestionBean unitQuestionPoll) throws EnMeExpcetion{
          final Question question = getQuestionDao().retrieveQuestionById(unitQuestionPoll.getId());
          if (question == null){
              throw new EnMeExpcetion("question not found");

File encuestame-business/src/main/java/org/encuestame/business/service/PollService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitFolder;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPoll;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.springframework.stereotype.Service;
 
 /**
     public void updateAnswersPoll( ){
     }
 
-    public void updateQuestionPoll(UnitQuestionBean unitQuestionPoll)
+    public void updateQuestionPoll(QuestionBean unitQuestionPoll)
             throws EnMeExpcetion {
         // TODO Auto-generated method stub
 

File encuestame-business/src/main/java/org/encuestame/business/service/SearchService.java

View file
  • Ignore whitespace
  * @since February 09, 2011
  * @version $Id$
  */
-public class SearchService extends ISearchService {
+public class SearchService extends AbstractIndexService  implements ISearchService {
 
     private Search search;
 

File encuestame-business/src/main/java/org/encuestame/business/service/SurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitAnswersBean;
 import org.encuestame.utils.web.UnitFolder;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitSurvey;
 import org.encuestame.utils.web.UnitSurveySection;
 import org.hibernate.HibernateException;
 
     /**
      * Create Question.
-     * @param questionBean {@link UnitQuestionBean}.
+     * @param questionBean {@link QuestionBean}.
      * @throws EnMeExpcetion exception
      */
-    public Question createQuestion(final UnitQuestionBean questionBean) throws EnMeExpcetion{
+    public Question createQuestion(final QuestionBean questionBean) throws EnMeExpcetion{
             final Question question = new Question();
             try{
 
 
     /**
      * Load all questions.
-     * @return List of {@link UnitQuestionBean}
+     * @return List of {@link QuestionBean}
      * @throws EnMeExpcetion exception
      */
-    public List<UnitQuestionBean> loadAllQuestions() throws EnMeExpcetion {
-        final List<UnitQuestionBean> listQuestionBean = new LinkedList<UnitQuestionBean>();
+    public List<QuestionBean> loadAllQuestions() throws EnMeExpcetion {
+        final List<QuestionBean> listQuestionBean = new LinkedList<QuestionBean>();
         try {
             final  List<Question> questionsList = getQuestionDao()
                     .loadAllQuestions();
             if (questionsList.size() > 0) {
 
                for (Question questions : questionsList) {
-                    final UnitQuestionBean q = new UnitQuestionBean();
+                    final QuestionBean q = new QuestionBean();
                     q.setId(Long.valueOf(questions.getQid().toString()));
                     q.setQuestionName(questions.getQuestion());
                     listQuestionBean.add(q);
         try {
             final SurveySection surveySectionDomain = new SurveySection();
             surveySectionDomain.setDescSection(surveySectionBean.getName());
-            for (final UnitQuestionBean questionBean : surveySectionBean.getListQuestions()) {
+            for (final QuestionBean questionBean : surveySectionBean.getListQuestions()) {
                 this.saveQuestions(questionBean);
             }
         } catch (Exception e) {
      * Save Questions.
      * @param questionBean
      */
-    public void saveQuestions(final UnitQuestionBean questionBean){
+    public void saveQuestions(final QuestionBean questionBean){
         final Question question = new Question();
         question.setQuestion(questionBean.getQuestionName());
         //	question.setQidKey();

File encuestame-business/src/main/java/org/encuestame/business/service/TweetPollService.java

View file
  • Ignore whitespace
 import org.encuestame.persistence.exception.EnmeFailOperation;
 import org.encuestame.utils.security.SocialAccountBean;
 import org.encuestame.utils.web.UnitFolder;
-import org.encuestame.utils.web.UnitHashTag;
+import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.UnitTweetPoll;
 import org.encuestame.utils.web.UnitTweetPollResult;
 
             }
             //Save Hash Tags for this tweetPoll.
             log.debug("HashTag Size"+tweetPollBean.getHashTags().size());
-            for (UnitHashTag unitHashTag : tweetPollBean.getHashTags()) {
+            for (HashTagBean unitHashTag : tweetPollBean.getHashTags()) {
                 HashTag hashTag = getHashTagDao().getHashTagByName(unitHashTag.getHashTagName().toLowerCase());
                 //If is null, create new hashTag.
                 if(hashTag == null){

File encuestame-business/src/main/java/org/encuestame/business/service/imp/IMasterSurveyService.java

View file
  • Ignore whitespace
 
 import org.encuestame.core.service.ServiceOperations;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
-import org.encuestame.utils.web.UnitHashTag;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.HashTagBean;
+import org.encuestame.utils.web.QuestionBean;
 
  /**
  * Master Survey Service Interface.
      * @param questionKeyword
      * @return
      */
-    List<UnitQuestionBean> listSuggestQuestion(final String questionKeyword, final String username) throws EnMeNoResultsFoundException;
+    List<QuestionBean> listSuggestQuestion(final String questionKeyword, final String username) throws EnMeNoResultsFoundException;
 
     /**
      * List Suggested Hash Tags.
      * @param maxResults
      * @return
      */
-    List<UnitHashTag> listSuggestHashTags(final String hashTagKeyWord, final Integer maxResults);
+    List<HashTagBean> listSuggestHashTags(final String hashTagKeyWord, final Integer maxResults);
 }

File encuestame-business/src/main/java/org/encuestame/business/service/imp/IPollService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitFolder;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPoll;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 
 /**
  * Poll Service Interface.
     * @param unitQuestionPoll
     * @throws EnMeExpcetion exception
     */
-    void updateQuestionPoll(final UnitQuestionBean unitQuestionPoll) throws EnMeExpcetion;
+    void updateQuestionPoll(final QuestionBean unitQuestionPoll) throws EnMeExpcetion;
 
     /**
     * Create Url Poll.

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ISearchService.java

View file
  • Ignore whitespace
  * @since February 09, 2011
  * @version $Id$
  */
-public class ISearchService {
+public interface ISearchService {
 
 }

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ISurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitAnswersBean;
 import org.encuestame.utils.web.UnitFolder;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 
 import twitter4j.TwitterException;
 import twitter4j.http.RequestToken;
 
     /**
      * Load all questions.
-     * @return List of {@link UnitQuestionBean}
+     * @return List of {@link QuestionBean}
      * @throws EnMeExpcetion exception
      */
-    List<UnitQuestionBean> loadAllQuestions() throws EnMeExpcetion;
+    List<QuestionBean> loadAllQuestions() throws EnMeExpcetion;
 
     /**
      * Load pattern info.
 
     /**
      * Create Question.
-     * @param questionBean {@link UnitQuestionBean}.
+     * @param questionBean {@link QuestionBean}.
      * @throws EnMeExpcetion exception
      */
-     Question createQuestion(final UnitQuestionBean questionBean) throws EnMeExpcetion;
+     Question createQuestion(final QuestionBean questionBean) throws EnMeExpcetion;
 
     /**
      * Retrieve Answer By Question Id.

File encuestame-business/src/main/java/org/encuestame/business/setup/ApplicationStartup.java

View file
  • Ignore whitespace
  * @author Picado, Juan juanATencuestame.org
  * @since Mar 15, 2011
  */
-public class ApplicationStartup implements Startup, InitializingBean {
+public class ApplicationStartup {
 
     public ApplicationStartup() {
         System.out.println("**********************ApplicationStartup*************************************");
     }
 
     public void startProcess() {
-        // TODO Auto-generated method stub
+        log.debug("*******************************");
+        log.debug("*                             *");
+        log.debug("*         STARTUP 1111           *");
+        log.debug("*                             *");
+        log.debug("*******************************");
 
     }
 
     public void afterPropertiesSet() throws Exception {
-        // TODO Auto-generated method stub
-
+        log.debug("*******************************");
+        log.debug("*                             *");
+        log.debug("*         SHUTHDOWN   222222        *");
+        log.debug("*                             *");
+        log.debug("*******************************");
     }
 }

File encuestame-business/src/test/java/org/encuestame/test/business/service/TestPollService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPatternBean;
 import org.encuestame.utils.web.UnitPoll;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.hibernate.HibernateException;
 import org.junit.Assert;
 import org.junit.Before;
      */
     @Test
     public void testcreatePoll() throws Exception{
-        final UnitQuestionBean question = ConvertDomainBean.convertQuestionsToBean(this.question);
+        final QuestionBean question = ConvertDomainBean.convertQuestionsToBean(this.question);
         final UnitPoll unitPoll = ConvertDomainBean.convertPollDomainToBean(this.poll);
         unitPoll.setQuestionBean(question);
         this.pollService.createPoll(unitPoll, this.userAccount.getUsername(), this.question);
          answers.add(createAnswersBean("ZXCVB", "Yes", this.question.getQid()));
          answers.add(createAnswersBean("ASDFG", "No", this.question.getQid()));
          patternBean = createPatternBean("radio.class", "radio buttons", "2", "Yes/No", "template.html");
-         final UnitQuestionBean unitQuestion = createUnitQuestion(this.question.getQid(), expectedResponse, 1L, this.user.getUid(), answers, patternBean);
+         final QuestionBean unitQuestion = createUnitQuestion(this.question.getQid(), expectedResponse, 1L, this.user.getUid(), answers, patternBean);
          pollService.updateQuestionPoll(unitQuestion);
          assertEquals(this.question.getQuestion(), expectedResponse);
      }
          answers.add(createAnswersBean("ZXCVB", "Yes", this.question.getQid()));
          answers.add(createAnswersBean("ASDFG", "No", this.question.getQid()));
          patternBean = createPatternBean("radio.class", "radio buttons", "2", "Yes/No", "template.html");
-         final UnitQuestionBean unitQuestion = createUnitQuestion(1L,"Why the sea is blue", 1L, this.user.getUid(), answers, patternBean);
+         final QuestionBean unitQuestion = createUnitQuestion(1L,"Why the sea is blue", 1L, this.user.getUid(), answers, patternBean);
          pollService.updateQuestionPoll(unitQuestion);
      }
 

File encuestame-business/src/test/java/org/encuestame/test/business/service/TestSearchService.java

View file
  • Ignore whitespace
 import org.encuestame.persistence.domain.survey.QuestionPattern;
 import org.encuestame.test.business.service.config.AbstractServiceBase;
 import org.encuestame.utils.web.UnitPoll;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
      */
     @Test
     public void testcreatePoll() throws Exception{
-        final UnitQuestionBean question = ConvertDomainBean.convertQuestionsToBean(this.question);
+        final QuestionBean question = ConvertDomainBean.convertQuestionsToBean(this.question);
         final UnitPoll unitPoll = ConvertDomainBean.convertPollDomainToBean(this.poll);
         unitPoll.setQuestionBean(question);
         assertNotNull(unitPoll);

File encuestame-business/src/test/java/org/encuestame/test/business/service/TestSurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.test.config.AbstractBaseUnitBeans;
 import org.encuestame.utils.web.UnitAnswersBean;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
     private List<UnitAnswersBean> answers;
 
-    /** {@link UnitQuestionBean} **/
-    private UnitQuestionBean questionBean;
+    /** {@link QuestionBean} **/
+    private QuestionBean questionBean;
 
     /** {@link UnitPatternBean}**/
     private UnitPatternBean patternBean;
      */
     @Test
     public void testloadAllQuestions() throws EnMeExpcetion{
-        final List<UnitQuestionBean> alist = surveyService.loadAllQuestions();
+        final List<QuestionBean> alist = surveyService.loadAllQuestions();
         assertEquals("Should be equals", 1, alist.size());
     }
 
      */
     @Test
     public void testSuggestionQuestionList() throws EnMeNoResultsFoundException{
-         List<UnitQuestionBean> unitQuestionBean = new ArrayList<UnitQuestionBean>();
+         List<QuestionBean> unitQuestionBean = new ArrayList<QuestionBean>();
         final String keyword = "sky";
         flushIndexes();
         unitQuestionBean = surveyService.listSuggestQuestion(keyword, this.userSecondary.getUsername());

File encuestame-business/src/test/java/org/encuestame/test/business/service/TestTweetPollService.java

View file
  • Ignore whitespace
 import org.encuestame.utils.security.SocialAccountBean;
 import org.encuestame.utils.web.UnitAnswersBean;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitTweetPoll;
 import org.encuestame.utils.web.UnitTweetPollResult;
 import org.junit.Before;
     /** {@link UnitPatternBean}**/
     private UnitPatternBean patternBean;
 
-    /** {@link UnitQuestionBean} **/
-    private UnitQuestionBean questionBean;
+    /** {@link QuestionBean} **/
+    private QuestionBean questionBean;
 
     /** List {@link UnitAnswersBean}. **/
     private List<UnitAnswersBean> answersSaveTweet;
     createQuestionAnswer("yes", question, "12345");
     createQuestionAnswer("no", question, "12346");
     final UnitTweetPoll tweetPollBean = new UnitTweetPoll();
-    final UnitQuestionBean questionBean = new UnitQuestionBean();
+    final QuestionBean questionBean = new QuestionBean();
     questionBean.setId(question.getQid());
     tweetPollBean.setQuestionBean(questionBean);
     tweetPollBean.setPublishPoll(true);

File encuestame-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitAnswersBean;
 import org.encuestame.utils.web.UnitFolder;
 import org.encuestame.utils.web.UnitGroupBean;
-import org.encuestame.utils.web.UnitHashTag;
+import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitLocationBean;
 import org.encuestame.utils.web.UnitLocationFolder;
 import org.encuestame.utils.web.UnitPermission;
 import org.encuestame.utils.web.UnitPoll;
 import org.encuestame.utils.web.UnitProjectBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitSessionUserBean;
 import org.encuestame.utils.web.UnitSurvey;
 import org.encuestame.utils.web.UnitTweetPoll;
     }
 
     /**
-     * Convert {@link HashTag} to {@link UnitHashTag}.
+     * Convert {@link HashTag} to {@link HashTagBean}.
      * @param hashTag name
      * @return
      */
-    public static final UnitHashTag convertHashTagDomain(final HashTag hashTag){
-        final UnitHashTag unitHashTag = new UnitHashTag();
+    public static final HashTagBean convertHashTagDomain(final HashTag hashTag){
+        final HashTagBean unitHashTag = new HashTagBean();
         unitHashTag.setHashTagName(hashTag.getHashTag());
         unitHashTag.setId(hashTag.getHashTagId());
         return unitHashTag;
     }
 
     /**
-     * Convert List of {@link HashTag} to List of {@link UnitHashTag}.
+     * Convert List of {@link HashTag} to List of {@link HashTagBean}.
      * @param tags list of tags
      * @return
      */
-    public static final  List<UnitHashTag> convertListHashTagsToBean(final List<HashTag> tags) {
-        final List<UnitHashTag> listTags = new ArrayList<UnitHashTag>();
+    public static final  List<HashTagBean> convertListHashTagsToBean(final List<HashTag> tags) {
+        final List<HashTagBean> listTags = new ArrayList<HashTagBean>();
         for (HashTag account : tags) {
             listTags.add(ConvertDomainBean.convertHashTagDomain(account));
         }
     }
 
     /**
-     * Convert {@link Question} to {@link UnitQuestionBean}.
+     * Convert {@link Question} to {@link QuestionBean}.
      * @param questions {@link Question}
-     * @return {@link UnitQuestionBean}
+     * @return {@link QuestionBean}
      */
-    public static final UnitQuestionBean convertQuestionsToBean(final Question questions){
-        final UnitQuestionBean questionBean = new UnitQuestionBean();
+    public static final QuestionBean convertQuestionsToBean(final Question questions){
+        final QuestionBean questionBean = new QuestionBean();
         questionBean.setId(questions.getQid());
         questionBean.setQuestionName(questions.getQuestion());
         questionBean.setUserId(questions.getAccountQuestion().getUid());
      * @return collection of question beans.
      * @throws Exception
      */
-    public static final List<UnitQuestionBean> convertListToUnitQuestionBean(final List<Question> questions){
-        final List<UnitQuestionBean> loadListQuestions = new LinkedList<UnitQuestionBean>();
+    public static final List<QuestionBean> convertListToUnitQuestionBean(final List<Question> questions){
+        final List<QuestionBean> loadListQuestions = new LinkedList<QuestionBean>();
             for (Question question : questions) {
                 loadListQuestions.add(ConvertDomainBean.convertQuestionsToBean(question));
             }

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/HashTagsJsonService.java

View file
  • Ignore whitespace
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
 import org.encuestame.mvc.controller.AbstractJsonController;
-import org.encuestame.utils.web.UnitHashTag;
+import org.encuestame.utils.web.HashTagBean;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
                     jsonResponse.put("hashtags", ListUtils.EMPTY_LIST);
                     setItemResponse(jsonResponse);
                 } else {
-                    final List<UnitHashTag> hashTags = getTweetPollService().listSuggestHashTags(keyword, limit);
+                    final List<HashTagBean> hashTags = getTweetPollService().listSuggestHashTags(keyword, limit);
                     log.debug("List Hash Tags "+hashTags.size());
                     setItemReadStoreResponse("hashTagName", "id", hashTags);
                 }

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/survey/PollJsonController.java

View file
  • Ignore whitespace
 import org.encuestame.mvc.controller.AbstractJsonController;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.utils.web.UnitPoll;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
                final Map<String, Object> sucess = new HashMap<String, Object>();
                if("create".equals(actionType)){
                    final UnitPoll unitPoll = new UnitPoll();
-                   final Question question =  getSurveyService().createQuestion(new UnitQuestionBean(questionName));
+                   final Question question =  getSurveyService().createQuestion(new QuestionBean(questionName));
                    unitPoll.setCreationDate(creationDate);
                    unitPoll.setCompletedPoll(completedPoll);
                    unitPoll.setCloseNotification(closeNotification);

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/survey/TweetPollJsonController.java

View file
  • Ignore whitespace
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.utils.security.SocialAccountBean;
 import org.encuestame.utils.web.UnitAnswersBean;
-import org.encuestame.utils.web.UnitHashTag;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.HashTagBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitTweetPoll;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
         log.debug("user " +user.getUsername());
         if (user != null) {
             // set user id to question bean.
-            final UnitQuestionBean questionBean = new UnitQuestionBean();
+            final QuestionBean questionBean = new QuestionBean();
             questionBean.setQuestionName(question);
             questionBean.setUserId(user.getUid());
             log.debug("questionBean.name() " +questionBean.getQuestionName());
                 //Setting Hash Tags
                 hashtags = hashtags == null ?  new String[0] : hashtags;
                 for (int row = 0; row < hashtags.length; row++) {
-                    final UnitHashTag hashTag = new UnitHashTag();
+                    final HashTagBean hashTag = new HashTagBean();
                     hashTag.setHashTagName(answers[row].toLowerCase().trim());
                     tweetPoll.getHashTags().add(hashTag);
                 }

File encuestame-mvc/src/main/java/org/encuestame/mvc/interceptor/SetupInterceptor.java

View file
  • Ignore whitespace
 
     protected Logger log = Logger.getLogger(this.getClass());
 
-    @Autowired
+    //@Autowired
     public Startup startup;
 
     @Override

File encuestame-mvc/src/main/java/org/encuestame/mvc/listener/EnMeContext.java

View file
  • Ignore whitespace
+package org.encuestame.mvc.listener;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.log4j.Logger;
+import org.encuestame.persistence.dao.jdbc.InstallerOperations;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.web.context.ContextLoaderListener;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Initialize encuestame context.
+ * Extend spring {@link ContextLoaderListener}.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 19, 2011
+ */
+public class EnMeContext extends ContextLoaderListener implements
+        ServletContextListener {
+
+    private static ServletContext servletContext = null;
+
+    protected Logger log = Logger.getLogger(this.getClass());
+
+    /**
+     * Constructor, inizialize parent context.
+     */
+    public EnMeContext() {
+        super();
+    }
+
+    /**
+     * On start application.
+     */
+    @Override
+    public void contextInitialized(final ServletContextEvent sce) {
+
+        this.servletContext = sce.getServletContext();
+
+        super.contextInitialized(sce);
+
+        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
+
+        log.debug("*******************************");
+        log.debug("*                             *");
+        log.debug("*         CONTEXT             *");
+        log.debug("*        "+ctx+"              *");
+        log.debug("*******************************");
+        log.debug("Testing get Bean Service "+ctx.getBean("installerDao"));
+        log.debug("Security Context "+SecurityContextHolder.getContext());
+        final InstallerOperations install = (InstallerOperations) ctx.getBean("installerDao");
+        log.debug("******************************* "+install);
+        install.checkDatabaseConection();
+        log.debug("*******************************");
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce) {
+    }
+}

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/jdbc/InstallerDao.java

View file
  • Ignore whitespace
+package org.encuestame.persistence.dao.jdbc;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.support.JdbcDaoSupport;
+import org.springframework.stereotype.Repository;
+
+@Repository("installerDao")
+public class InstallerDao extends JdbcDaoSupport implements InstallerOperations {
+
+    @Autowired
+    public InstallerDao(JdbcTemplate jdbcTemplate) {
+        setJdbcTemplate(jdbcTemplate);
+    }
+
+    public void startInstall() {
+        // getJdbcTemplate().
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.persistence.dao.jdbc.InstallerOperations#checkDatabaseConection()
+     */
+    public void checkDatabaseConection() {
+        getJdbcTemplate().execute("select 1");
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.persistence.dao.jdbc.InstallerOperations#checkIfDatabaseIsInstalled()
+     */
+    public boolean checkIfDatabaseIsInstalled() {
+        getJdbcTemplate().execute("select 1");
+        return false;
+    }
+
+    public void executeInitialData() {
+        // TODO Auto-generated method stub
+
+    }
+}

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/jdbc/InstallerOperations.java

View file
  • Ignore whitespace
+
+package org.encuestame.persistence.dao.jdbc;
+
+/**
+ * Have a installation support.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 19, 2011
+ */
+public interface InstallerOperations {
+
+    /**
+     * Start database installations.
+     */
+    public void startInstall();
+
+
+    /**
+     * Execute sql
+     */
+    public void executeInitialData();
+
+    /**
+     *
+     */
+    public void checkDatabaseConection();
+
+    /**
+     *
+     * @return
+     */
+    public boolean checkIfDatabaseIsInstalled();
+}

File encuestame-persistence/src/test/java/org/encuestame/test/config/AbstractBaseUnitBeans.java

View file
  • Ignore whitespace
 import org.encuestame.utils.web.UnitLocationBean;
 import org.encuestame.utils.web.UnitLocationFolder;
 import org.encuestame.utils.web.UnitPatternBean;
-import org.encuestame.utils.web.UnitQuestionBean;
+import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitTweetPoll;
 import org.encuestame.utils.web.UserAccountBean;
 
      * @return
      */
     @SuppressWarnings("unchecked")
-    public UnitQuestionBean createUnitQuestionBean(
+    public QuestionBean createUnitQuestionBean(
             final String questionName,
             final Long stateId,
             final Long userId,
             final List listAnswers,
             final UnitPatternBean pattern){
-         final UnitQuestionBean question = new UnitQuestionBean();
+         final QuestionBean question = new QuestionBean();
          question.setQuestionName(questionName);
          question.setStateId(stateId);
          question.setUserId(userId);
              final Date scheduleDate,
              final String tweetUrl,
              final Long userId,
-             final UnitQuestionBean questionBean,
+             final QuestionBean questionBean,
              final String userTwitterAccount
 
              ){
              final Boolean publishPoll,
              final String tweetUrl,
              final Long userId,
-             final UnitQuestionBean questionBean,
+             final QuestionBean questionBean,
              final String userTwitterAccount
 
              ){
       * @return
       */
      @SuppressWarnings("unchecked")
-     public UnitQuestionBean createUnitQuestion(
+     public QuestionBean createUnitQuestion(
              final Long questionId,
              final String questionName,
              final Long stateId,
              final Long userId,
              final List listAnswers,
              final UnitPatternBean pattern){
-          final UnitQuestionBean question = new UnitQuestionBean();
+          final QuestionBean question = new QuestionBean();
           question.setId(questionId);
           question.setQuestionName(questionName);
           question.setStateId(stateId);

File encuestame-search/fastVector.html

View file
  • Ignore whitespace
+<html><body><p>QUERY : brown</p>0 : quick <b style="background:yellow">brown</b> fox jumps over the lazy dog<br/></body></html>

File encuestame-search/pom.xml

View file
  • Ignore whitespace
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
         </dependency>
-    <dependency>
-        <groupId>org.apache.poi</groupId>
-        <artifactId>poi-ooxml</artifactId>
+        <dependency>
+     	   <groupId>org.apache.poi</groupId>
+     	   <artifactId>poi-ooxml</artifactId>
         </dependency>
         <dependency>
             <groupId>pdfbox</groupId>
             <artifactId>pdfbox</artifactId>
         </dependency>
-    </dependencies>
+	<dependency>
+	    <groupId>org.apache.lucene</groupId>
+   	    <artifactId>lucene-highlighter</artifactId>
+       </dependency> 
+	<dependency>
+	    <groupId>org.apache.lucene</groupId>
+   	    <artifactId>lucene-fast-vector-highlighter</artifactId>
+       </dependency>
+       <dependency>
+	   <groupId>org.apache.lucene</groupId>
+           <artifactId>lucene-spellchecker</artifactId>
+       </dependency>
+    </dependencies> 
 </project>

File encuestame-search/src/main/java/org/encuestame/search/main/CreateSpellCheckerIndex.java

View file
  • Ignore whitespace
+package org.encuestame.search.main;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.spell.LuceneDictionary;
+import org.apache.lucene.search.spell.SpellChecker;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+
+public class CreateSpellCheckerIndex {
+    public static void main(String[] args) throws IOException {
+        if (args.length != 3) {
+        System.out.println("Usage: java lia.tools.SpellCheckerTest " +
+        "SpellCheckerIndexDir IndexDir IndexField");
+        System.exit(1);
+        }
+        String spellCheckDir = args[0]; // SpellCheck Directory
+        String indexDir = args[1]; // Index Directory
+        String indexField = args[2]; // field to Index.
+        System.out.println("Now build SpellChecker index...");
+        // Open Spellchecker Index
+        Directory dir = FSDirectory.open(new File(spellCheckDir));
+        // Create Spellchecker
+        SpellChecker spell = new SpellChecker(dir);
+        long startTime = System.currentTimeMillis();
+
+        Directory dir2 = FSDirectory.open(new File(indexDir));
+
+        IndexReader r = IndexReader.open(dir2,true);
+        try {
+        spell.indexDictionary(new LuceneDictionary(r, indexField));
+        } finally {
+        r.close();
+        }
+        dir.close();
+        dir2.close();
+        long endTime = System.currentTimeMillis();
+        System.out.println(" took " + (endTime-startTime) + " milliseconds");
+        }
+        }
+
+

File encuestame-search/src/main/java/org/encuestame/search/main/FastVectorHighlighterSample.java

View file
  • Ignore whitespace
+package org.encuestame.search.main;
+
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.vectorhighlight.BaseFragmentsBuilder;
+import org.apache.lucene.search.vectorhighlight.FastVectorHighlighter;
+import org.apache.lucene.search.vectorhighlight.FieldQuery;
+import org.apache.lucene.search.vectorhighlight.FragListBuilder;
+import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
+import org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder;
+import org.apache.lucene.search.vectorhighlight.SimpleFragListBuilder;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
+
+public class FastVectorHighlighterSample {
+
+    static final String[] DOCS = {
+    " The quick brown fox jumps over the lazy dog",
+    " quick gold fox jumped over the lazy black dog",
+    " quick fox jumps over the black dog",
+    " red fox jumped over the lazy dark gray dog"};
+
+    static final String QUERY = "brown";
+            //"quick OR fox OR \"lazy dog\"~1";
+    static final String F = "f";
+    static Directory dir = new RAMDirectory();
+    static Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
+
+    public static void main(String[] args) throws Exception {
+        System.out.println("ARGUMENTS-->"+args[0]);
+        if (args.length != 1) {
+        System.err.println("Usage: FastVectorHighlighterSample <filename>");
+        System.exit(-1);
+        }
+        makeIndex();
+        searchIndex(args[0]);
+        }
+
+        static void makeIndex() throws IOException {
+            IndexWriter writer = new IndexWriter(dir, analyzer, true, MaxFieldLength.UNLIMITED);
+            for(String d : DOCS){
+                Document doc = new Document();
+                doc.add(new Field(F, d, Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
+                writer.addDocument(doc);
+            }
+            writer.close();
+        }
+
+
+        static void searchIndex(String filename) throws Exception {
+        QueryParser parser = new QueryParser(Version.LUCENE_29, F, analyzer);
+
+        Query query = parser.parse(QUERY);
+        FastVectorHighlighter highlighter = getHighlighter();
+        FieldQuery fieldQuery = highlighter.getFieldQuery(query);
+        IndexSearcher searcher = new IndexSearcher(dir, true);
+        TopDocs docs = searcher.search(query, 10);
+
+        FileWriter writer = new FileWriter(filename);
+        writer.write("<html>");
+        writer.write("<body>");
+        writer.write("<p>QUERY : " + QUERY + "</p>");
+        for(ScoreDoc scoreDoc : docs.scoreDocs) {
+             String snippet = highlighter.getBestFragment( fieldQuery, searcher.getIndexReader(),
+                     scoreDoc.doc, F, 100 );
+             if (snippet != null) {
+                 writer.write(scoreDoc.doc + " : " + snippet + "<br/>");
+             }
+         }
+         writer.write("</body></html>");
+         writer.close();
+         searcher.close();
+        }
+
+        static FastVectorHighlighter getHighlighter() {
+             FragListBuilder fragListBuilder = new SimpleFragListBuilder();
+             FragmentsBuilder fragmentBuilder = new ScoreOrderFragmentsBuilder(BaseFragmentsBuilder.COLORED_PRE_TAGS, BaseFragmentsBuilder.COLORED_POST_TAGS);
+             return new FastVectorHighlighter(true, true, fragListBuilder, fragmentBuilder);
+
+        }
+        }

File encuestame-search/src/main/java/org/encuestame/search/main/HighlightIt.java

View file
  • Ignore whitespace
+package org.encuestame.search.main;
+
+import java.io.FileWriter;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.highlight.Highlighter;
+import org.apache.lucene.search.highlight.QueryScorer;
+import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
+import org.apache.lucene.search.highlight.SimpleSpanFragmenter;
+import org.apache.lucene.util.Version;
+
+/**
+ *
+ * @author dmorales
+ *
+ */
+public class HighlightIt  {
+
+    /** Text **/
+    private static final String text =
+        "In this section we'll show you how to make the simplest " +
+        "programmatic query, searching for a single term, and then " +
+        "we'll see how to use QueryParser to accept textual queries." +
+        "In the sections that follow, we’ll take this simple example" +
+        "further by detailing all the query types built into Lucene." +
+        "We begin with the simplest search of all: searching for all" +
+        "documents that contain a single term.";
+    public static void main(String[] args) throws Exception {
+        if (args.length != 1) {
+            System.err.println("Usage: HighlightIt <filename-out>");
+            System.exit(-1);
+        }
+        String filename = args[0];
+        String searchText = "section";
+        /** Create the query **/
+        QueryParser parser = new QueryParser(Version.LUCENE_29, "f", new StandardAnalyzer(Version.LUCENE_29));
+        Query query = parser.parse(searchText);
+
+        /** Customize tags**/
+        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");
+        /** Tokenize text **/
+        TokenStream tokens = new StandardAnalyzer(Version.LUCENE_29).tokenStream("f", new StringReader(text));
+
+        /** Create Query Score **/
+        QueryScorer scorer = new QueryScorer(query, "f");
+
+        Highlighter highlighter = new Highlighter(formatter, scorer);
+
+        highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
+        /** Highlight best 3 fragments **/
+        String result = highlighter.getBestFragments(tokens, text, 3, "...");
+
+        /** Write highlighted in Html **/
+
+        FileWriter writer = new FileWriter(filename);
+        writer.write("<html>");
+        writer.write("<style>\n" +
+                ".highlight {\n" +
+                " background: yellow;\n" +
+                "}\n" +
+        "</style>");
+        writer.write("<body>");
+        writer.write(result);
+        writer.write("</body></html>");
+        writer.close();
+    }
+}

File encuestame-search/src/main/java/org/encuestame/search/main/SpellCheckerExample.java

View file
  • Ignore whitespace
+package org.encuestame.search.main;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.spell.LevensteinDistance;
+import org.apache.lucene.search.spell.SpellChecker;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+
+public class SpellCheckerExample {
+    public static void main(String[] args) throws IOException {
+
+        System.out.println("First Parameter"+args[0]);
+        if (args.length != 2) {
+        System.out.println("Usage: java lia.tools.SpellCheckerTest " +
+        "SpellCheckerIndexDir wordToRespell");
+        System.exit(1);
+        }
+        String spellCheckDir = args[0];
+        String wordToRespell = args[1];
+        Directory dir = FSDirectory.open(new File(spellCheckDir));
+        if (!IndexReader.indexExists(dir)) {
+        System.out.println("\nERROR: No spellchecker index at path \"" +
+        spellCheckDir + "\"; please run CreateSpellCheckerIndex first\n");
+        System.exit(1);
+        }
+        SpellChecker spell = new SpellChecker(dir);
+        spell.setStringDistance(new LevensteinDistance());
+        String[] suggestions = spell.suggestSimilar( wordToRespell, 3);
+        System.out.println(suggestions.length + " suggestions for '" + wordToRespell + "':");
+        //String suggestion;
+        for (String suggestion : suggestions) {
+            System.out.println(" " + suggestion);
+        }
+
+        }
+        }
+
+

File encuestame-search/src/main/resources/IndexTest1/segments.gen

  • Ignore whitespace
Binary file modified.

File encuestame-search/src/main/resources/IndexTest1/segments_2

  • Ignore whitespace
Binary file modified.

File encuestame-search/src/test/java/org/encuestame/search/TestSearch.java

View file
  • Ignore whitespace
 import java.io.File;
 import java.io.IOException;
 
-import org.apache.lucene.analysis.StopAnalyzer;
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopDocs;
-
+import org.apache.lucene.search.highlight.Highlighter;
+import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
+import org.apache.lucene.search.highlight.QueryScorer;
+import org.apache.lucene.search.highlight.SimpleSpanFragmenter;
+import org.apache.lucene.search.highlight.TokenSources;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
-
 import org.apache.lucene.util.Version;
-
-
-import junit.framework.TestCase;
+import org.encuestame.search.main.TestUtil;
 
 /**
  * Test Service Search.
     public void testSearcher() throws CorruptIndexException, IOException, ParseException{
 
         Directory directory = FSDirectory.open(new File(indexDir));
+
         //IndexReader reader = IndexReader.open(indexDir);
         //IndexSearcher searcher = new IndexSearcher(reader);
         IndexSearcher searcher = null;
+
         QueryParser parser = new QueryParser(Version.LUCENE_29, "content",
 
                     new StandardAnalyzer(Version.LUCENE_29));
             searcher.close(); // Close IndexSearcher.
             //System.out.println("Total number of docs "+reader.maxDoc());
         }
+    /**
+     *
+     * @throws IOException
+     * @throws InvalidTokenOffsetsException
+     */
+    public void testHits() throws IOException, InvalidTokenOffsetsException  {
+        IndexSearcher searcher = new IndexSearcher(TestUtil.getBookIndexDirectory(), true);
+        TermQuery query = new TermQuery(new Term("title", "action"));
+        TopDocs hits = searcher.search(query, 10);
+        QueryScorer scorer = new QueryScorer(query, "title");
+        Highlighter highlighter = new Highlighter(scorer);
+        highlighter.setTextFragmenter(
+                new SimpleSpanFragmenter(scorer));
+        Analyzer analyzer = new SimpleAnalyzer();
+        for (ScoreDoc sd : hits.scoreDocs) {
+                Document doc = searcher.doc(sd.doc);
+                String title = doc.get("title");
+                TokenStream stream = TokenSources.getAnyTokenStream(searcher.getIndexReader(),
+                        sd.doc, "title", doc, analyzer);
+                String fragment = highlighter.getBestFragment(stream, title);
+                System.out.println(fragment);
+            }
+}
 }

File encuestame-utils/src/main/java/org/encuestame/utils/web/AbstractUnitSurvey.java

View file
  • Ignore whitespace
 
 
     /** List of HashTags. **/
-    private List<UnitHashTag> hashTags = new ArrayList<UnitHashTag>();
+    private List<HashTagBean> hashTags = new ArrayList<HashTagBean>();
 
     /**
      * @return the hashTags
      */
-    public final List<UnitHashTag> getHashTags() {
+    public final List<HashTagBean> getHashTags() {
         return hashTags;
     }
 
     /**
      * @param hashTags the hashTags to set
      */
-    public final void setHashTags(List<UnitHashTag> hashTags) {
+    public final void setHashTags(List<HashTagBean> hashTags) {
         this.hashTags = hashTags;
     }
 }

File encuestame-utils/src/main/java/org/encuestame/utils/web/HashTagBean.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.utils.web;
+
+import java.io.Serializable;
+
+/**
+ * Unit Hash Tag.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 31, 2010 7:49:45 AM
+ * @version $Id:$
+ */
+public class HashTagBean implements Serializable {
+
+    /**
+     * Serial
+     */
+    private static final long serialVersionUID = -56061660495067820L;
+
+    /** Name. **/
+    private String hashTagName;
+
+    /** Id. **/
+    private Long id;
+
+    /** Constructor. **/
+    public HashTagBean() {}
+
+
+    /** Constructor. **/
+    public HashTagBean(String hashTagName) {
+        super();
+        this.hashTagName = hashTagName;
+    }
+
+    /**
+     * @return the hashTagName
+     */
+    public final String getHashTagName() {
+        return hashTagName;
+    }
+
+    /**
+     * @param hashTagName the hashTagName to set
+     */
+    public final void setHashTagName(String hashTagName) {
+        this.hashTagName = hashTagName;
+    }
+
+    /**
+     * @return the id
+     */
+    public final Long getId() {
+        return id;
+    }
+
+    /**
+     * @param id the id to set
+     */
+    public final void setId(Long id) {
+        this.id = id;
+    }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((hashTagName == null) ? 0 : hashTagName.hashCode());
+        return result;
+    }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        HashTagBean other = (HashTagBean) obj;
+        if (hashTagName == null) {
+            if (other.hashTagName != null)
+                return false;
+        } else if (!hashTagName.equals(other.hashTagName)) {
+            return false;
+        }
+        return true;
+    }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(
+                getHashTagName());
+        return builder.toString();
+    }
+}

File encuestame-utils/src/main/java/org/encuestame/utils/web/QuestionBean.java

View file
  • Ignore whitespace
+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.utils.web;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Unit Question Bean.
+ *
+ * @author Picado, Juan juanATencuestame.org
+ * @since 01/06/2009 15:22:10
+ * @version $Id$
+ **/
+public class QuestionBean implements Serializable {
+
+    /**
+     * Serial.
+     */
+    private static final long serialVersionUID = -3106607865655197340L;
+
+
+    private String questionName = new String("");
+    /**
+     *
+     */
+    private String version;
+
+    /**
+     *