Skip to main content

Focus

Struct Focus 

Source
pub struct Focus {
    pub query: Query,
    /* private fields */
}
Expand description

查询和从它派生的打分规则。

Fields§

§query: Query

Implementations§

Source§

impl Focus

Source

pub fn new(query: &str) -> Focus

Source

pub fn note_seed_language(&mut self, lang: Option<&str>)

记下种子页声明的语言。

Source

pub fn found_english_home(&mut self)

记下抓到了本站的英文版首页(见 Self::is_language_portal)。

Source

pub fn with_host(self, host: &str) -> Focus

记下种子页的主机(见 Self::same_host)。

Source

pub fn observe_page(&mut self, page: &PageSignal)

记下一页(正文命中的词、各方面的证据),调整词权重和本站统计量。抓到的每一页都要记 (包括无用页:正是它们说明哪些词常见)。

Source

pub fn page_signal( &self, url: &Url, title: Option<&str>, markdown: &str, links: usize, lang: Option<&str>, ) -> PageSignal

相关度的组成(见 [Self::page_relevance]):词权重变了以后按它重算。

Source

pub fn relevance(&self, p: &PageSignal) -> f32

Source

pub fn weights_moved(&mut self) -> bool

词权重和上次重新打分时比变得够多了(变化最大的词差 [RESCORE_DELTA] 以上): 排队链接的分数要按新权重重算。返回 true 时记下现在的权重。

一个链接的分数。parent 是所在页面的相关度,depth 是链接目标的深度。

链接分数的组成(见 Self::score):命中了哪些词、所在页面、URL 的形状和深度。 存下它,词权重变了以后不用再看一遍页面就能重算分数。

Source

pub fn score(&self, s: &LinkSignal) -> f32

链接的分数:锚文本、URL、所在行按当前词权重的覆盖率,加上所在页面的相关度, 按 URL 的形状打折或给保底分,再按深度衰减。

Source

pub fn learn(&mut self, s: &LinkSignal, hit: bool) -> bool

记下一个链接抓回来的页面是否相关,更新链接权重。权重变了时返回 true, 排队的链接要按新权重重新打分。直接给定分数的链接(种子页、hreflang)没有特征,不学。

Source

pub fn is_language_portal(&self, url: &Url) -> bool

这一页是不是本站英文版的首页(/en/、/en.html、/top/en/),而且是第一个: 它是第二个首页,链接不多衰减一层(它下面的 /en/studies/ 按一级栏目算,见 [section])。

Source

pub fn alternate_score(&self, lang: &str, depth: usize) -> Option<f32>

种子页用 hreflang 声明的英文版的分数(英文查询、还没找到英文首页时):和英文入口一样, 深度不加(同一页的另一种语言);别的语言、别的页面声明的都是 None(每一页都声明自己的 英文版,跟着走就成了按语言重抓一遍)。

Auto Trait Implementations§

§

impl Freeze for Focus

§

impl RefUnwindSafe for Focus

§

impl Send for Focus

§

impl Sync for Focus

§

impl Unpin for Focus

§

impl UnsafeUnpin for Focus

§

impl UnwindSafe for Focus

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more