public ChapterBean() {

    HttpServletRequest hsr =
        (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String url = hsr.getParameter("url").replace(".html", "");
    int idx = url.lastIndexOf("-");
    int chapter = Integer.parseInt(url.substring(idx + 1, url.length()));
    String book = url.substring(0, idx).replace("-", " ");

    int bookId = CachedData.getBibleBooks().getByName(book).getId();
    BibleVerses verses = BibleVerses.loadByBookIdChapterNumber(bookId, chapter);
    passage = BiblePassage.load(verses.get(0).getId(), verses.get(verses.size() - 1).getId());
    if (passage == null) {
      passage = new BiblePassage();
      passage.setStartVerseId(verses.get(0).getId());
      passage.setEndVerseId(verses.get(verses.size() - 1).getId());
      passage.save();
      Topics.generateForPassage(
          passage.getId(), passage.getStartVerseId(), passage.getEndVerseId());
    }
    passage.populateVerses(AppUser.getCurrent().TranslationId);

    commentsController = new CommentsController("passage", passage.getId());
    relatedTopicsController = new RelatedTopicsController("passage", passage.getId(), 5);
    relatedImagesController =
        new RelatedImagesController("passage", passage.getId(), passage.getUrl());
  }
  public SearchBean() {
    HttpServletRequest hsr =
        (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    javax.servlet.http.HttpServletResponse response =
        (javax.servlet.http.HttpServletResponse)
            FacesContext.getCurrentInstance().getExternalContext().getResponse();
    String term = hsr.getParameter("q").trim();

    if (term.length() < 1) {
      try {
        response.sendRedirect("/");
      } catch (Exception ex) {
      }
    }

    BiblePassage passage = BiblePassage.parse(term, CachedData.getBibleBooks(), true);
    if (passage != null) {
      try {
        response.sendRedirect("/bible/" + passage.getUrl());
      } catch (Exception ex) {
      }
    } else {

      if (!term.contains(" ")) {
        String baseWord = Topic.getBaseWord(term);
        Topic topic = Topic.loadByBaseWord(baseWord);
        if (topic != null) {
          try {
            response.sendRedirect("/topics/" + topic.getUrl());
          } catch (Exception ex) {
          }
        }
      } else {
        int verseId = TextSearch.findMatch(term);
        passage = BiblePassage.load(verseId, verseId);
        passage.populateVerses(AppUser.getCurrent().TranslationId);
        try {
          response.sendRedirect("/bible/" + passage.getUrl());
        } catch (Exception ex) {
        }
      }
    }
  }