var searchModule=function(n){var t={book:[],bookCount:0,site:[],siteCount:0,maxSpeed:0,bookChanging:!1},i={onShowRecord:function(){},onBeforeShowResult:function(){},onAfterShowResult:function(){}},r=this,f,e,u;for(u in n)i[u]&&(i[u]=n[u]);return this.hash=function(n){return n.toLowerCase()},this.setKey=function(n){f=n},this.addSite=function(n){t.site[n]=[]},this.addResult=function(n){var i,u;t.bookChanging=!0,bookKey=r.hash(n.title),i=n.site,n.speed||(n.speed=0),n.speedWidth=Math.max(0,Math.min(n.speed/256*100,100)),t.book[bookKey]=t.book[bookKey]||[],u=t.book[bookKey].push(n),u>1&&(t.book[bookKey]=_.sortBy(t.book[bookKey],function(n){return 0-(n.num+n.speedWidth/100)})),n.speed>t.maxSpeed&&(t.maxSpeed=n.speed),t.site[i].push({book:bookKey,site:i,sitename:n.sitename})==1&&t.siteCount++},this.showResult=function(n){var f=[],o,s,h,r,u,e,c;for(r in t.book)(!n||n&&r.indexOf(n)>-1)&&f.push({num:t.book[r].length,title:r});for(f=_.sortBy(f,function(n){return n.num}),o=f.length;o--;)if(s=f[o],h=s.num,h!=0){if(r=s.title,u=t.book[r][0],!u.author||!u.chapter)for(e=1,c=t.book[r].length;e<c;e++)if(u.author||(u.author=t.book[r][e].author),u.chapter||(u.author=t.book[r][e].chapter),u.chapter&&u.author)break;if(i.onShowRecord(o,u,h,n))break}},this.getChapter=function(n,i){var u=t.book[r.hash(n)]||[];_.chain(u).each(i)},this.bookCount=function(){var n,i;if(t.bookChanging){n=0;for(i in t.book)n++;t.bookCount=n}return t.bookCount},this.siteCount=function(){return t.siteCount},this.startEvent=function(){},this.stopEvent=function(){clearInterval(e)},e=setInterval(function(){if(t.bookChanging){t.bookChanging=!1;i.onBeforeShowResult(r.bookCount(),r.siteCount());r.showResult(f),i.onAfterShowResult()}},1500),this}