pub struct KnowledgeBaseIndex {
pub pages: HashMap<PageId, PageMeta>,
pub sorted_ids: Vec<PageId>,
pub index_issues: Vec<ParseIssue>,
pub duplicate_ids: Vec<DuplicateId>,
/* private fields */
}Expand description
Indexed knowledge base metadata with lazy page loading.
Fields§
§pages: HashMap<PageId, PageMeta>Metadata map keyed by canonical page id.
sorted_ids: Vec<PageId>Page ids in case-insensitive title sort order, computed at open time,
maintained by Self::register_page.
index_issues: Vec<ParseIssue>Non-fatal issues encountered while scanning metadata.
duplicate_ids: Vec<DuplicateId>Ids claimed by more than one .lepiter file, captured during KnowledgeBase::open
before the collision is lost to pages.
Implementations§
Source§impl KnowledgeBaseIndex
impl KnowledgeBaseIndex
Sourcepub fn register_page(&mut self, meta: PageMeta)
pub fn register_page(&mut self, meta: PageMeta)
Registers a page in the index, inserting it at the correct sorted position via binary search. If the page already exists, its old sort position is removed first so re-registration never creates duplicates (and handles title changes correctly).
The exact-title index is kept in sync as well: on a title change the page id is moved from its stale title bucket to the new one, and now-empty buckets are dropped.
Sourcepub fn load_page(&self, id: &str) -> Result<Page>
pub fn load_page(&self, id: &str) -> Result<Page>
Loads and parses a single page by canonical id.
Returns an error if the id is missing from the index or if JSON parsing fails.
Sourcepub fn sorted_pages(&self) -> Vec<&PageMeta>
pub fn sorted_pages(&self) -> Vec<&PageMeta>
Returns metadata entries in cached title-sorted order.
Sourcepub fn filter_page_ids(&self, query: &str) -> Vec<PageId> ⓘ
pub fn filter_page_ids(&self, query: &str) -> Vec<PageId> ⓘ
Returns page ids filtered by metadata query (title/id/tags), sorted by title.
Sourcepub fn filter_page_ids_scored(
&self,
query: &str,
) -> Vec<(PageId, SearchMatchKind)>
pub fn filter_page_ids_scored( &self, query: &str, ) -> Vec<(PageId, SearchMatchKind)>
Returns page ids with their match kinds, filtered by metadata query.
Sourcepub fn search_hits(&self, query: &str, include_content: bool) -> Vec<SearchHit>
pub fn search_hits(&self, query: &str, include_content: bool) -> Vec<SearchHit>
Searches pages by metadata and optionally content, returning hits ranked by relevance (title > tag > content), with ties broken alphabetically by title.
Sourcepub fn resolve_page_id_by_title(&self, title: &str) -> TitleResolution
pub fn resolve_page_id_by_title(&self, title: &str) -> TitleResolution
Resolves a page id from title using case-insensitive exact match, then partial match.
Sourcepub fn resolve_page_id_by_title_exact(&self, title: &str) -> TitleResolution
pub fn resolve_page_id_by_title_exact(&self, title: &str) -> TitleResolution
Resolves a page id from title using a case-insensitive exact match
only, never falling back to a substring like Self::resolve_page_id_by_title.
Used for wikilink/page:/title: resolution, where a substring hit would
fabricate a graph edge and hide a genuinely broken link.
Sourcepub fn classify_link_target(&self, raw: &str) -> LinkTargetKind
pub fn classify_link_target(&self, raw: &str) -> LinkTargetKind
Classifies a raw link target for navigation/open behavior.
Sourcepub fn build_backlinks(&mut self)
pub fn build_backlinks(&mut self)
Builds the reverse link index by loading every page, extracting link targets, classifying them, and recording which pages link to which.
Call this once after KnowledgeBase::open when backlink data is needed.
Sourcepub fn update_backlinks_for(&mut self, page_id: &str)
pub fn update_backlinks_for(&mut self, page_id: &str)
Incrementally updates the backlinks index for a single page.
Removes any existing outgoing links from page_id, then re-extracts
and classifies its current links. Much cheaper than a full
Self::build_backlinks call when only one page changed.
Sourcepub fn backlinks_for(&self, id: &str) -> &[PageId] ⓘ
pub fn backlinks_for(&self, id: &str) -> &[PageId] ⓘ
Returns the page ids that link to the given page, sorted by title.
Sourcepub fn build_link_graph(&self) -> LinkGraph
pub fn build_link_graph(&self) -> LinkGraph
Builds the full directed link graph across all pages.
Each edge represents one internal page-to-page link (deduplicated per source/target pair). Self-links are excluded.
Sourcepub fn attachment_resolver(&self) -> AttachmentResolver
pub fn attachment_resolver(&self) -> AttachmentResolver
Returns an attachment resolver rooted at this knowledge base.
Sourcepub fn scan_all_pages(&self) -> LinkAnalysisResult
pub fn scan_all_pages(&self) -> LinkAnalysisResult
Scans all pages in a single pass, collecting broken links, linked pages, link graph edges, missing attachments, and load errors.
Sourcepub fn analyze_all(&self) -> LinkAnalysisResult
pub fn analyze_all(&self) -> LinkAnalysisResult
alias for Self::scan_all_pages.
Sourcepub fn analyze_links(&self) -> LinkAnalysisResult
pub fn analyze_links(&self) -> LinkAnalysisResult
alias for Self::scan_all_pages.
Sourcepub fn orphan_ids(
&self,
linked_pages: &HashSet<PageId>,
toc_page_id: Option<&str>,
) -> Vec<PageId> ⓘ
pub fn orphan_ids( &self, linked_pages: &HashSet<PageId>, toc_page_id: Option<&str>, ) -> Vec<PageId> ⓘ
Returns page ids that are not linked to by any other page.
The toc_page_id (table-of-contents), when present, is excluded from the
result since it serves as the root entry point and is not expected to be
linked to.
Sourcepub fn find_duplicate_titles(&self) -> Vec<DuplicateTitle>
pub fn find_duplicate_titles(&self) -> Vec<DuplicateTitle>
Finds page titles shared by more than one page (case-insensitive).
Sourcepub fn find_duplicate_ids(&self) -> Vec<DuplicateId>
pub fn find_duplicate_ids(&self) -> Vec<DuplicateId>
Returns page ids claimed by more than one file, captured at open time.
Sourcepub fn find_missing_attachments(&self) -> Vec<MissingAttachment>
pub fn find_missing_attachments(&self) -> Vec<MissingAttachment>
Finds attachment references whose files are missing from disk; see
LinkAnalysisResult::missing_attachments.
Trait Implementations§
Source§impl Clone for KnowledgeBaseIndex
impl Clone for KnowledgeBaseIndex
Source§fn clone(&self) -> KnowledgeBaseIndex
fn clone(&self) -> KnowledgeBaseIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more