EntityLinker.h header
#include <ew/app/EntityLinker.h>
Namespace ew::app
EntityLinker class
class ew::app::EntityLinker
Finds mentions of a project's entities in text so they can be turned into links. Names are matched whole-word and case-insensitively. Construct over a project, then call rebuild() whenever the project's entities change to refresh the name index.
When two entities answer to the same name, the strongest claim wins, decided by meaning rather than by indexing order: the project's own entity beats a mounted library's – the same project-first rule MountedLibraries::find(), ownerOf() and isWritable() apply – and an entity that BEARS the name beats one that merely lists it as an alias. Two entities sharing a primary name within one repo is a duplicate the writer created, with no principled winner; the first in id order keeps the name, which is stable, so the link does not move under them.
The two-argument constructor additionally indexes the names of every entity in the project's mounted libraries, so a shared-library entity auto-links in prose exactly like a local one; the resolved id then resolves across the span at click/hover time.
Members
ew::app::search::EntityLinker::EntityLinker(const ew::core::project::Project &project)
Constructs a linker that indexes the entity names of project. project must outlive this linker.
ew::app::search::EntityLinker::EntityLinker(const ew::core::project::Project &project, const app::library::MountedLibraries &libraries)
Like the single-argument constructor, but also indexes the entities of every library mounted into project via libraries, so their names auto-link too. libraries must outlive this linker.
void ew::app::search::EntityLinker::rebuild()
Rebuilds the name index and match pattern from the current project state.
std::vector< EntityMention > ew::app::search::EntityLinker::findMentions(QStringView text) const
Returns every entity-name mention in text, in order of appearance.
EntityMention struct
struct ew::app::EntityMention
One occurrence in text of an entity's display name, resolved to that entity.
Members
qsizetype ew::app::search::EntityMention::offset = 0
Code-unit offset of the mention within the analyzed text.
qsizetype ew::app::search::EntityMention::length = 0
Length of the mention in code units.
ew::core::foundation::ContentId ew::app::search::EntityMention::target
The entity the mention refers to.
bool operator==(const EntityMention &, const EntityMention &)=default
Mentions compare equal when every field matches.