?? adaptiverevisitfrontier.html
字號:
<a name="262" href="#262">262</a> alreadyIncluded = <strong>null</strong>;<a name="263" href="#263">263</a> }<a name="264" href="#264">264</a> <a name="265" href="#265">265</a> loadSeeds();<a name="266" href="#266">266</a> }<a name="267" href="#267">267</a> <a name="268" href="#268">268</a> <em>/**<em>*</em></em><a name="269" href="#269">269</a> <em> * Create a UriUniqFilter that will serve as record </em><a name="270" href="#270">270</a> <em> * of already seen URIs.</em><a name="271" href="#271">271</a> <em> *</em><a name="272" href="#272">272</a> <em> * @return A UURISet that will serve as a record of already seen URIs</em><a name="273" href="#273">273</a> <em> * @throws IOException</em><a name="274" href="#274">274</a> <em> */</em><a name="275" href="#275">275</a> <strong>protected</strong> <a href="../../../../org/archive/crawler/datamodel/UriUniqFilter.html">UriUniqFilter</a> createAlreadyIncluded() throws IOException {<a name="276" href="#276">276</a> <a href="../../../../org/archive/crawler/datamodel/UriUniqFilter.html">UriUniqFilter</a> uuf = <strong>new</strong> <a href="../../../../org/archive/crawler/util/BdbUriUniqFilter.html">BdbUriUniqFilter</a>(<a name="277" href="#277">277</a> <strong>this</strong>.controller.getBdbEnvironment());<a name="278" href="#278">278</a> uuf.setDestination(<strong>this</strong>);<a name="279" href="#279">279</a> <strong>return</strong> uuf;<a name="280" href="#280">280</a> }<a name="281" href="#281">281</a> <a name="282" href="#282">282</a> <em>/**<em>*</em></em><a name="283" href="#283">283</a> <em> * Loads the seeds</em><a name="284" href="#284">284</a> <em> * <p></em><a name="285" href="#285">285</a> <em> * This method is called by initialize() and kickUpdate()</em><a name="286" href="#286">286</a> <em> */</em><a name="287" href="#287">287</a> <strong>public</strong> <strong>void</strong> loadSeeds() {<a name="288" href="#288">288</a> Writer ignoredWriter = <strong>new</strong> StringWriter();<a name="289" href="#289">289</a> <em class="comment">// Get the seeds to refresh.</em><a name="290" href="#290">290</a> Iterator iter = <strong>this</strong>.controller.getScope().seedsIterator(ignoredWriter);<a name="291" href="#291">291</a> <strong>while</strong> (iter.hasNext()) {<a name="292" href="#292">292</a> <a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> caUri =<a name="293" href="#293">293</a> CandidateURI.createSeedCandidateURI((UURI)iter.next());<a name="294" href="#294">294</a> caUri.setSchedulingDirective(CandidateURI.MEDIUM);<a name="295" href="#295">295</a> schedule(caUri);<a name="296" href="#296">296</a> }<a name="297" href="#297">297</a> batchFlush();<a name="298" href="#298">298</a> <em class="comment">// save ignored items (if any) where they can be consulted later</em><a name="299" href="#299">299</a> AbstractFrontier.saveIgnoredItems(<a name="300" href="#300">300</a> ignoredWriter.toString(), <a name="301" href="#301">301</a> controller.getDisk());<a name="302" href="#302">302</a> }<a name="303" href="#303">303</a> <a name="304" href="#304">304</a> <strong>public</strong> String getClassKey(<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> cauri) {<a name="305" href="#305">305</a> String queueKey = (String)getUncheckedAttribute(cauri,<a name="306" href="#306">306</a> ATTR_FORCE_QUEUE);<a name="307" href="#307">307</a> <strong>if</strong> (<span class="string">""</span>.equals(queueKey)) {<a name="308" href="#308">308</a> <em class="comment">// Typical case, barring overrides</em><a name="309" href="#309">309</a> queueKey =<a name="310" href="#310">310</a> queueAssignmentPolicy.getClassKey(controller, cauri);<a name="311" href="#311">311</a> <em class="comment">// The queueAssignmentPolicy is always based on Hostnames</em><a name="312" href="#312">312</a> <em class="comment">// We may need to remove any www[0-9]{0,}\. prefixes from the</em><a name="313" href="#313">313</a> <em class="comment">// hostnames</em><a name="314" href="#314">314</a> <strong>if</strong>(((Boolean)getUncheckedAttribute(<a name="315" href="#315">315</a> cauri,ATTR_QUEUE_IGNORE_WWW)).booleanValue()){<a name="316" href="#316">316</a> queueKey = queueKey.replaceAll(<span class="string">"^www[0-9]{0,}//."</span>,<span class="string">""</span>);<a name="317" href="#317">317</a> }<a name="318" href="#318">318</a> }<a name="319" href="#319">319</a> <strong>return</strong> queueKey;<a name="320" href="#320">320</a> }<a name="321" href="#321">321</a> <a name="322" href="#322">322</a> <em>/**<em>*</em></em><a name="323" href="#323">323</a> <em> * Canonicalize passed uuri. Its would be sweeter if this canonicalize</em><a name="324" href="#324">324</a> <em> * function was encapsulated by that which it canonicalizes but because</em><a name="325" href="#325">325</a> <em> * settings change with context -- i.e. there may be overrides in operation</em><a name="326" href="#326">326</a> <em> * for a particular URI -- its not so easy; Each CandidateURI would need a</em><a name="327" href="#327">327</a> <em> * reference to the settings system. That's awkward to pass in.</em><a name="328" href="#328">328</a> <em> * </em><a name="329" href="#329">329</a> <em> * @param uuri Candidate URI to canonicalize.</em><a name="330" href="#330">330</a> <em> * @return Canonicalized version of passed <code>uuri</code>.</em><a name="331" href="#331">331</a> <em> */</em><a name="332" href="#332">332</a> <strong>protected</strong> String canonicalize(<a href="../../../../org/archive/net/UURI.html">UURI</a> uuri) {<a name="333" href="#333">333</a> <strong>return</strong> Canonicalizer.canonicalize(uuri, <strong>this</strong>.controller.getOrder());<a name="334" href="#334">334</a> }<a name="335" href="#335">335</a> <a name="336" href="#336">336</a> <em>/**<em>*</em></em><a name="337" href="#337">337</a> <em> * Canonicalize passed CandidateURI. This method differs from</em><a name="338" href="#338">338</a> <em> * {@link #canonicalize(UURI)} in that it takes a look at</em><a name="339" href="#339">339</a> <em> * the CandidateURI context possibly overriding any canonicalization effect if</em><a name="340" href="#340">340</a> <em> * it could make us miss content. If canonicalization produces an URL that</em><a name="341" href="#341">341</a> <em> * was 'alreadyseen', but the entry in the 'alreadyseen' database did</em><a name="342" href="#342">342</a> <em> * nothing but redirect to the current URL, we won't get the current URL;</em><a name="343" href="#343">343</a> <em> * we'll think we've already see it. Examples would be archive.org</em><a name="344" href="#344">344</a> <em> * redirecting to www.archive.org or the inverse, www.netarkivet.net</em><a name="345" href="#345">345</a> <em> * redirecting to netarkivet.net (assuming stripWWW rule enabled).</em><a name="346" href="#346">346</a> <em> * <p>Note, this method under circumstance sets the forceFetch flag.</em><a name="347" href="#347">347</a> <em> * </em><a name="348" href="#348">348</a> <em> * @param cauri CandidateURI to examine.</em><a name="349" href="#349">349</a> <em> * @return Canonicalized <code>cacuri</code>.</em><a name="350" href="#350">350</a> <em> */</em><a name="351" href="#351">351</a> <strong>protected</strong> String canonicalize(<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> cauri) {<a name="352" href="#352">352</a> String canon = canonicalize(cauri.getUURI());<a name="353" href="#353">353</a> <strong>if</strong> (cauri.isLocation()) {<a name="354" href="#354">354</a> <em class="comment">// If the via is not the same as where we're being redirected (i.e.</em><a name="355" href="#355">355</a> <em class="comment">// we're not being redirected back to the same page, AND the</em><a name="356" href="#356">356</a> <em class="comment">// canonicalization of the via is equal to the the current cauri, </em><a name="357" href="#357">357</a> <em class="comment">// THEN forcefetch (Forcefetch so no chance of our not crawling</em><a name="358" href="#358">358</a> <em class="comment">// content because alreadyseen check things its seen the url before.</em><a name="359" href="#359">359</a> <em class="comment">// An example of an URL that redirects to itself is:</em><a name="360" href="#360">360</a> <em class="comment">// http://bridalelegance.com/images/buttons3/tuxedos-off.gif.</em><a name="361" href="#361">361</a> <em class="comment">// An example of an URL whose canonicalization equals its via's</em><a name="362" href="#362">362</a> <em class="comment">// canonicalization, and we want to fetch content at the</em><a name="363" href="#363">363</a> <em class="comment">// redirection (i.e. need to set forcefetch), is netarkivet.dk.</em><a name="364" href="#364">364</a> <strong>if</strong> (!cauri.toString().equals(cauri.getVia().toString()) &&<a name="365" href="#365">365</a> canonicalize(cauri.getVia()).equals(canon)) {<a name="366" href="#366">366</a> cauri.setForceFetch(<strong>true</strong>);<a name="367" href="#367">367</a> }<a name="368" href="#368">368</a> }<a name="369" href="#369">369</a> <strong>return</strong> canon;<a name="370" href="#370">370</a> }<a name="371" href="#371">371</a> <a name="372" href="#372">372</a> <em>/**<em>*</em></em><a name="373" href="#373">373</a> <em> * </em><a name="374" href="#374">374</a> <em> * @param caUri The URI to schedule.</em><a name="375" href="#375">375</a> <em> */</em><a name="376" href="#376">376</a> <strong>protected</strong> <strong>void</strong> innerSchedule(<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> caUri) {<a name="377" href="#377">377</a> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi;<a name="378" href="#378">378</a> <strong>if</strong>(caUri instanceof <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a>) {<a name="379" href="#379">379</a> curi = (CrawlURI) caUri;<a name="380" href="#380">380</a> } <strong>else</strong> {<a name="381" href="#381">381</a> curi = CrawlURI.from(caUri,System.currentTimeMillis());<a name="382" href="#382">382</a> curi.putLong(A_TIME_OF_NEXT_PROCESSING,<a name="383" href="#383">383</a> System.currentTimeMillis());<a name="384" href="#384">384</a> <em class="comment">// New CrawlURIs get 'current time' as the time of next processing.</em><a name="385" href="#385">385</a> }<a name="386" href="#386">386</a> <a name="387" href="#387">387</a> <strong>if</strong>(curi.getClassKey() == <strong>null</strong>){<a name="388" href="#388">388</a> curi.setClassKey(getClassKey(curi));<a name="389" href="#389">389</a> }<a name="390" href="#390">390</a> <a name="391" href="#391">391</a> <strong>if</strong>(curi.isSeed() && curi.getVia() != <strong>null</strong><a name="392" href="#392">392</a> && curi.flattenVia().length() > 0) {<a name="393" href="#393">393</a> <em class="comment">// The only way a seed can have a non-empty via is if it is the</em><a name="394" href="#394">394</a> <em class="comment">// result of a seed redirect. Add it to the seeds list.</em><a name="395" href="#395">395</a> <em class="comment">//</em><a name="396" href="#396">396</a> <em class="comment">// This is a feature. This is handling for case where a seed</em>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -