• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benwbrum / fromthepage / 13528664866

25 Feb 2025 06:48PM UTC coverage: 59.626% (-2.2%) from 61.822%
13528664866

Pull #4471

github

web-flow
Merge 279229e31 into 3b7156fe3
Pull Request #4471: Search test

1548 of 3188 branches covered (48.56%)

Branch coverage included in aggregate %.

84 of 457 new or added lines in 18 files covered. (18.38%)

1 existing line in 1 file now uncovered.

7065 of 11257 relevant lines covered (62.76%)

78.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.14
/app/controllers/display_controller.rb
1
class DisplayController < ApplicationController
1✔
2
  public :render_to_string
1✔
3

4
  protect_from_forgery :except => [:set_note_body]
1✔
5

6
  PAGES_PER_SCREEN = 5
1✔
7

8
  def read_work
1✔
9
    if params.has_key?(:work_id)
61✔
10
      @work = Work.friendly.find(params[:work_id])
61!
11
    elsif params.has_key?(:id)
×
12
      @work = Work.friendly.find(params[:id])
×
13
    elsif params.has_key?(:url)
×
14
      @work = Work.find_by_id(params[:url][:work_id])
×
15
    end
16
    if params.has_key?(:needs_review)
61✔
17
      @review = params[:needs_review]
9✔
18
    end
19
    @total = @work.pages.count
61✔
20
    if @article
61✔
21
      # restrict to pages that include that subject
×
22
      redirect_to :action => 'read_all_works', :article_id => @article.id, :page => 1 and return
×
23
    else
61✔
24
      if @review == 'review'
61✔
25
        @pages = @work.pages.review.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
2✔
26
        @count = @pages.count
2✔
27
        @heading = t('.pages_need_review')
2✔
28
      elsif @review == 'incomplete'
59!
29
        @pages = @work.pages.incomplete.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
×
30
        @count = @pages.count
×
31
        @heading = t('.pages_need_completion')
✔
32
      elsif @review == 'transcription'
59✔
33
        @pages = @work.pages.needs_transcription.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
1✔
34
        @count = @pages.count
1✔
35
        @incomplete_pages = @work.pages.needs_completion.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
1✔
36
        @incomplete_count = @incomplete_pages.count
1✔
37
        @heading = t('.pages_need_transcription')
1✔
38
      elsif @review == 'index'
58!
39
        @pages = @work.pages.needs_index.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
×
40
        @count = @pages.count
×
41
        @heading = t('.pages_need_indexing')
✔
42
      elsif @review == 'translation'
58✔
43
        @pages = @work.pages.needs_translation.order('position').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
1✔
44
        @count = @pages.count
1✔
45
        @heading = t('.pages_need_translation')
1✔
46
      elsif @review == 'translation_review'
57✔
47
        @pages = @work.pages.translation_review.paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
2✔
48
        @count = @pages.count
2✔
49
        @heading = t('.translations_need_review')
2✔
50
      elsif @review == 'translation_index'
55!
51
        @pages = @work.pages.needs_translation_index.paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
×
52
        @count = @pages.count
×
53
        @heading = t('.translations_need_indexing')
×
54
      else
55✔
55
        @pages = @work.pages.paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
55✔
56
        @count = @pages.count
55✔
57
        @heading = t('.pages')
55✔
58
      end
59
    end
60
    session[:col_id] = @collection.slug
61✔
61
  end
62

63
  def read_all_works
1✔
64
    if @article
2✔
65
      # restrict to pages that include that subject
2✔
66
      @pages = Page.order('work_id, position').joins('INNER JOIN page_article_links pal ON pages.id = pal.page_id').where([ 'pal.article_id = ?', @article.id ]).where(work_id: @collection.works.ids).paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
2✔
67
      @pages.distinct!
2✔
68
      @heading = t('.pages_that_mention', article: @article.title)
2✔
69
    else
×
70
      @pages = Page.paginate :all, :page => params[:page],
×
71
                                        :order => 'work_id, position',
72
                                        :per_page => 5
73
      @heading = t('.pages')
×
74
    end
75
    session[:col_id] = @collection.slug
2✔
76
  end
77

78
  def paged_search
1✔
79
    if @article
×
80
      render plain: "This functionality has been disabled.  Please contact support@frothepage.com if you need it."
×
81
      return
×
82

83
      session[:col_id] = @collection.slug
×
84
      # get the unique search terms
85
      terms = []
×
86
      @search_string = ""
×
87
      @article.page_article_links.each do |link|
×
88
        terms << link.display_text.gsub(/\s+/, ' ')
×
89
      end
90
      terms.uniq!
×
91
      # process them for display and search
92
      terms.each do |term|
×
93
        # don't add required text
94
        if term.match(/ /)
×
95
          @search_string += "\"#{term}\" "
×
96
        else
×
97
          @search_string += term + "* "
×
98
        end
99
      end
100
      if params[:unlinked_only]
×
101
        conditions =
102
          ["MATCH(search_text) AGAINST(? IN BOOLEAN MODE)"+
×
103
          " AND pages.id not in "+
104
          "    (SELECT page_id FROM page_article_links WHERE article_id = ?)",
105
          @search_string,
106
          @article.id]
107

108
      else
×
109
        conditions =
110
          ["MATCH(search_text) AGAINST(? IN BOOLEAN MODE)",
×
111
          @search_string]
112
      end
113
      @pages = Page.order('work_id, position').joins(:work).where(work_id: @collection.works.ids).where(conditions).paginate(page: params[:page])
×
114
    else
×
115
      @search_attempt = SearchAttempt.find_by(slug: params[:id])
×
116
      session[:search_attempt_id] = @search_attempt.id if session[:search_attempt_id] != @search_attempt.id
×
117

118
      # restrict to pages that include that subject
119
      @collection = @search_attempt.collection || @search_attempt.document_set || @search_attempt.work.collection
×
120
      @work = @search_attempt&.work
×
NEW
121
      if ELASTIC_ENABLED
×
NEW
122
        search_mode = nil
×
NEW
123
        search_slug = nil
×
124

NEW
125
        if @search_attempt.search_type == "collection"
×
NEW
126
          if @search_attempt.collection.present?
×
NEW
127
            search_mode = 'collection'
×
NEW
128
            search_slug = @search_attempt.collection.slug
×
NEW
129
          elsif @search_attempt.document_set.present?
×
NEW
130
            search_mode = 'docset'
×
NEW
131
            search_slug = @search_attempt.document_set.slug
×
132
          end
×
NEW
133
        elsif @search_attempt.search_type == "work"
×
NEW
134
          if @search_attempt.work.present?
×
NEW
135
            search_mode = 'work'
×
NEW
136
            search_slug = @search_attempt.work.slug
×
137
          end
138
        end
139

140
        # TODO: Need metrics tracking from new_landing search
141
        # Redirect to "findaproject" tabbed search results
NEW
142
        redirect_to controller: 'dashboard',
×
143
                    action: 'landing_page',
144
                    search: @search_attempt.query,
145
                    mode: search_mode,
146
                    slug: search_slug
147
      else
×
NEW
148
        pages = @search_attempt.query_results
×
NEW
149
        @pages = pages.paginate(page: params[:page])
×
150
      end
UNCOV
151
      @search_string = params[:id].split('-')[0...-1].join(' ')
×
152
    end
153
    logger.debug "DEBUG #{@search_string}"
×
154
  end
155
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc