Revision 1411:6487f22bee9d plugins/redmine_bibliography/app/controllers

View differences:

plugins/redmine_bibliography/app/controllers/publications_controller.rb
214 214
    @object_name = "publications[authorships_attributes][#{object_id}][search_results]"
215 215

  
216 216
    # cc 20110909 -- revert to like instead of like_unique -- see #289
217
    authorships_list = Authorship.like(params[:term]).find(:all, :limit => 100)
217
    authorships_list = Authorship.like(params[:term]).group('author_id').find(:all, :limit => 100)
218

  
219
    authors_list = authorships_list.collect do |x| x.author end
220

  
218 221
    users_list = User.active.like(params[:term]).find(:all, :limit => 100)
219 222

  
220
    logger.debug "Query for \"#{params[:term]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users"
223
    logger.debug "Query for \"#{params[:term]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users"
221 224

  
222
    @results = users_list
225
    # will check if any of the members of the users list
226
    #  doesn't belong to the authors list
223 227

  
224
    # TODO: can be optimized…
225
    authorships_list.each do |authorship|
226
      flag = true
228
    @results = authors_list
227 229

  
228
      users_list.each do |user|
229
        if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution
230
          Rails.logger.debug { "Rejecting Authorship #{authorship.id}" }
231
          flag = false
232
          break
233
        end
234
      end
235

  
236
      @results << authorship if flag
230
    users_list.each do |user|
231
      @results << user unless authors_list.include?(user.author)
237 232
    end
238 233

  
239 234
    render :layout => false

Also available in: Unified diff