当我插入超过 100,000 条记录时,我似乎遇到了这个错误。我知道它可以支持的远不止这些。错误如下和相关类的代码。
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 2015-07-01 08:14:24.512:INFO:/:Processing by SearchController#search as HTML| 2015-07-01 08:14:24.512:INFO:/: Parameters: {"type"=>"digital_object"}| Jul 01, 2015 8:14:24 AM org.apache.solr.core.SolrCore execute INFO: [collection1] webapp= path=/select params={facet=true&sort=title_sort+asc&facet.limit=100&qf=four_part_id^3+title^2+finding_aid_filing_title^2+fullrecord&wt=json&rows=10&defType=edismax&pf=four_part_id^4&start=0&q=*:*&facet.field=repository&facet.field=primary_type&facet.field=subjects&facet.field=source&facet.field=linked_agent_roles&fq=types:("digital_object")&fq=-exclude_by_default:true&fq=publish:true} hits=203799 status=0 QTime=15 2015-07-01 08:14:24.590:INFO:/: Rendered G:/archivesspace/plugins/vva/public/views/search/_components_switch.html.erb (15.0ms)| 2015-07-01 08:14:24.590:INFO:/: Rendered search/_filter.html.erb (0.0ms)| 2015-07-01 08:14:24.606:INFO:/: Rendered search/_pagination_summary.html.erb (16.0ms)| 2015-07-01 08:14:24.637:INFO:/: Rendered search/_inline_results.html.erb (47.0ms)| 2015-07-01 08:14:24.637:INFO:/: Rendered search/results.html.erb within layouts/application (62.0ms)| 2015-07-01 08:14:24.653:INFO:/:Completed 500 Internal Server Error in 141.0ms| 2015-07-01 08:14:24.653:INFO:/:|ActionView::Template::Error (undefined method `strip!' for nil:NilClass):| 17: <% elsif result["primary_type"] ==="repository" %>| 18: <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %>| 19: <% else %>| 20: <%= link_to title_or_finding_aid_filing_title( result ) , :controller => :records, :action => result["primary_type"], :id => id, :repo_id => repo_id %>| 21: <% end %>| 22: | 23: | app/helpers/application_helper.rb:22:in `title_or_finding_aid_filing_title'| app/views/search/_inline_results.html.erb:20:in `_app_views_search__inline_results_html_erb___996910774_15116'| app/views/search/_inline_results.html.erb:5:in `_app_views_search__inline_results_html_erb___996910774_15116'| app/helpers/application_helper.rb:134:in `render_aspace_partial'| app/views/search/results.html.erb:13:in `_app_views_search_results_html_erb__332589766_15048'| app/controllers/search_controller.rb:21:in `search'| app/controllers/search_controller.rb:20:in `search'||| |
_inline_results.html.erb
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <%= render_aspace_partial :partial =>"search/pagination_summary", :locals => {:search_data => search_data} %> <ul class="results-list"> <% search_data['results'].each do |result| %> <% id = JSONModel(result["primary_type"]).id_for(result['uri']) repo_id = JSONModel(:repository).id_for(JSONModel.repository_for(result['uri']),{}, true) %> <li class="result"> <%= icon_for result["primary_type"] %> <% if result["primary_type"] ==="subject" %> <%= link_to result["title"], {"filter_term" => search_data.facet_query_string("subjects", result["title"])} %> <% elsif ["agent_person","agent_software","agent_family","agent_corporate_entity"].include?(result["primary_type"]) %> <%= link_to result['title'], :controller => :records, :action => :agent, :id => id, :agent_type => result["primary_type"] %> <% elsif result["primary_type"] ==="repository" %> <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> <% else %> <%= link_to title_or_finding_aid_filing_title( result ) , :controller => :records, :action => result["primary_type"], :id => id, :repo_id => repo_id %> <% end %> <%= render_aspace_partial :partial =>"search/result_summary_#{result["primary_type"]}", :locals => {:obj => result} %> </li> <% end %> </ul> <%= render_aspace_partial :partial =>"search/pagination", :locals => {:search_data => search_data} %> <% else %> <p class="alert alert-info"> <%= I18n.t("search_results.no_results") %>. </p> <% end %> |
search_controller.rb
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | class SearchController < ApplicationController DETAIL_TYPES = ['accession', 'resource', 'archival_object', 'digital_object', 'digital_object_component', 'classification', 'agent_person', 'agent_family', 'agent_software', 'agent_corporate_entity'] VIEWABLE_TYPES = ['agent', 'repository', 'subject'] + DETAIL_TYPES FACETS = ["repository","primary_type","subjects","source","linked_agent_roles"] def search set_search_criteria @search_data = Search.all(@criteria, @repositories) @term_map = params[:term_map] ? ASUtils.json_parse(params[:term_map]) : {} respond_to do |format| format.html { render"search/results" } format.js { render_aspace_partial :partial =>"search/inline_results", :content_type =>"text/html", :locals => {:search_data => @search_data} } end end def advanced_search set_advanced_search_criteria @search_data = Search.all(@criteria, @repositories) render"search/results" end def repository set_search_criteria if params[:repo_id].blank? @search_data = Search.all(@criteria.merge({"facet[]" => [],"type[]" => ["repository"]}), {}) return render"search/results" end @repository = @repositories.select{|repo| JSONModel(:repository).id_for(repo.uri).to_s === params[:repo_id]}.first @breadcrumbs = [ [@repository['repo_code'], url_for(:controller => :search, :action => :repository, :id => @repository.id),"repository"] ] @search_data = Search.repo(@repository.id, @criteria, @repositories) render"search/results" end private def set_search_criteria @criteria = params.select{|k,v| ["page","q","type","sort", "filter_term","root_record","format"].include?(k) and not v.blank? } @criteria["page"] ||= 1 @criteria["sort"] ="title_sort asc" unless @criteria["sort"] or @criteria["q"] or params["advanced"].present? if @criteria["filter_term"] @criteria["filter_term[]"] = Array(@criteria["filter_term"]).reject{|v| v.blank?} @criteria.delete("filter_term") end if params[:type].blank? @criteria['type[]'] = DETAIL_TYPES else @criteria['type[]'] = Array(params[:type]).keep_if {|t| VIEWABLE_TYPES.include?(t)} @criteria.delete("type") end @criteria['exclude[]'] = params[:exclude] if not params[:exclude].blank? @criteria['facet[]'] = FACETS end def set_advanced_search_criteria set_search_criteria terms = (0..2).collect{|i| term = search_term(i) if term and term["op"] ==="NOT" term["op"] ="AND" term["negated"] = true end term }.compact if not terms.empty? @criteria["aq"] = AdvancedQueryBuilder.new(terms, :public).build_query.to_json @criteria['facet[]'] = FACETS end end def search_term(i) if not params["v#{i}"].blank? {"field" => params["f#{i}"],"value" => params["v#{i}"],"op" => params["op#{i}"],"type" =>"text" } end end end |
application_helper.rb
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | def include_theme_css css ="" css += stylesheet_link_tag("themes/#{ArchivesSpacePublic::Application.config.public_theme}/bootstrap", :media =>"all") css += stylesheet_link_tag("themes/#{ArchivesSpacePublic::Application.config.public_theme}/application", :media =>"all") css.html_safe end def set_title(title) @title = title end def title_or_finding_aid_filing_title(resource) if resource["finding_aid_filing_title"] && !resource["finding_aid_filing_title"].nil? && resource["finding_aid_filing_title"].length > 0 title = resource["finding_aid_filing_title"] elsif resource["title"] && !resource["title"].nil? title = resource["title"] else title = resource["display_string"] end MixedContentParser::parse(title, url_for(:root)) end def icon_for(type) "<span class='icon-#{type}' title='#{I18n.t("#{type}._singular")}'></span>".html_safe end def label_and_value(label, value) return if value.blank? label = content_tag(:dt, label) value = content_tag(:dd, value) label + value end def i18n_enum(jsonmodel_type, property, value) return if value.blank? property_defn = JSONModel(jsonmodel_type).schema["properties"][property] return if property_defn.nil? if property_defn.has_key?"dynamic_enum" enum_key = property_defn["dynamic_enum"] #return"enumerations.#{enum_key}.#{value}" I18n.t("enumerations.#{enum_key}.#{value}", :default => value) else I18n.t("#{jsonmodel_type}.#{property}_#{value}", :default => value) end end def params_for_search(opts = {}) search_params = { :controller => :search, :action => :search } search_params["filter_term"] = Array(opts["filter_term"] || params["filter_term"]).clone search_params["filter_term"].concat(Array(opts["add_filter_term"])) if opts["add_filter_term"] search_params["filter_term"] = search_params["filter_term"].reject{|f| Array(opts["remove_filter_term"]).include?(f)} if opts["remove_filter_term"] search_params["sort"] = opts["sort"] || params["sort"] search_params["q"] = opts["q"] || params["q"] search_params["format"] = params["format"] search_params["root_record"] = params["root_record"] search_params["agent_type"] = params["agent_type"] search_params["page"] = opts["page"] || params["page"] || 1 if opts["type"] && opts["type"].kind_of?(Array) search_params["type"] = opts["type"] else search_params["type"] = opts["type"] || params["type"] end search_params["term_map"] = params["term_map"] # retain any advanced search params advanced = (opts["advanced"] || params["advanced"]) search_params["advanced"] = advanced.blank? || advanced === 'false' ? false : true search_params[:action] = :advanced_search if search_params["advanced"] (0..2).each do |i| search_params["v#{i}"] = params["v#{i}"] search_params["f#{i}"] = params["f#{i}"] search_params["op#{i}"] = params["op#{i}"] end search_params.reject{|k,v| k.blank? or v.blank?} end def set_title_for_search title = I18n.t("actions.search") if @search_data if params[:type] && !@search_data.types.blank? title ="#{I18n.t("search_results.searching")} #{@search_data.types.join(",")}" end facets_to_display = [] if @search_data.query? facets_to_display << @search_data.facet_label_for_query end if @search_data.filtered_terms? facets_to_display << @search_data[:criteria]["filter_term[]"].collect{|filter_term| @search_data.facet_label_for_filter(filter_term)} end if facets_to_display.length > 0 title +=" | #{facets_to_display.join(",")}" end end set_title(title) end def truncate(string, length = 50, trailing = '…') return string if string.length < length "#{string[0..50]}#{trailing}".html_safe end # See: ApplicationController#render_aspace_partial def render_aspace_partial(args) defaults = {:formats => [:html], :handlers => [:erb]} return render(defaults.merge(args)) end def proxy_localhost? AppConfig[:frontend_proxy_url] =~ /localhost/ end end |
我明白了。看起来一些导入的数据有空白标题"。通过更新它们,它能够工作。
错误在你的 _inline_results.html.erb...
2 | <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> |
错误是结果['title'] 为 nil。所以,添加这行代码....
2 3 4 | <% if !result['title'].blank? %> <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> <% end %> |
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits