Skip to content

Commit 05b73da

Browse files
committed
include more symbols in the lunr search, and deprioritize deprecated and @_spi symbols in search results
1 parent f1c51dc commit 05b73da

File tree

9 files changed

+68
-16
lines changed

9 files changed

+68
-16
lines changed

Assets/js/Main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/js/Main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import JSON
2+
3+
extension Unidoc.Linker.TreeMapper
4+
{
5+
enum Flags:Int
6+
{
7+
case deprecated = 0
8+
case spi = 1
9+
}
10+
}
11+
extension Unidoc.Linker.TreeMapper.Flags:JSONEncodable, JSONDecodable
12+
{
13+
}

Sources/UnidocLinker/Sema/Unidoc.Linker.TreeMapper.swift

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,45 @@ extension Unidoc.Linker.TreeMapper
4444
{
4545
self.local[vertex.id] = (vertex.shoot, vertex.flags)
4646

47+
var flags:Flags?
48+
{
49+
if !vertex.signature.availability.isGenerallyRecommended
50+
{
51+
return .deprecated
52+
}
53+
else if case _? = vertex.signature.spis
54+
{
55+
return .spi
56+
}
57+
else
58+
{
59+
return nil
60+
}
61+
}
62+
4763
switch vertex.phylum
4864
{
4965
case .actor, .class, .struct, .enum, .protocol, .macro(.attached):
5066
self.trees[vertex.culture, default: []].types[vertex.shoot] =
5167
(.culture, vertex.flags)
5268

53-
case .func(nil), .var(nil), .macro(.freestanding):
54-
// Global procedures show up in search, but not in the type tree.
55-
self.trees[vertex.culture, default: []].procs.append(vertex.shoot)
69+
case .typealias:
70+
// Typealiases show up in search, but not in the type tree. Typealiases are often
71+
// deprecated, and disappear from signatures. That’s why people search for them.
72+
fallthrough
73+
74+
case .associatedtype, .case, .func, .macro(.freestanding), .var:
75+
// Don’t include C declarations in search.
76+
if vertex.flags.cdecl
77+
{
78+
break
79+
}
80+
81+
self.trees[vertex.culture, default: []].extra.append((vertex.shoot, flags))
5682

57-
case _:
58-
return
83+
case .operator, .deinitializer, .initializer, .subscript:
84+
// These all look the same, so they probably wouldn’t be very useful in search.
85+
break
5986
}
6087
}
6188
}
@@ -206,12 +233,13 @@ extension Unidoc.Linker.TreeMapper
206233
$0["h"] = noun.shoot.hash?.value
207234
}
208235
}
209-
for shoot:Unidoc.Shoot in members.procs
236+
for (shoot, flags):(Unidoc.Shoot, Flags?) in members.extra
210237
{
211238
$0[+, Any.self]
212239
{
213240
$0["s"] = shoot.stem.rawValue
214241
$0["h"] = shoot.hash?.value
242+
$0["f"] = flags
215243
}
216244
}
217245
}

Sources/UnidocLinker/Sema/Unidoc.Linker.TreeMembers.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ extension Unidoc.Linker
66
struct TreeMembers
77
{
88
var articles:[Unidoc.Noun]
9-
var procs:[Unidoc.Shoot]
109
var types:[Unidoc.Shoot: (Unidoc.Citizenship, Phylum.DeclFlags)]
10+
var extra:[(Unidoc.Shoot, TreeMapper.Flags?)]
1111

1212
private
1313
init(articles:[Unidoc.Noun],
14-
procs:[Unidoc.Shoot],
15-
types:[Unidoc.Shoot: (Unidoc.Citizenship, Phylum.DeclFlags)])
14+
types:[Unidoc.Shoot: (Unidoc.Citizenship, Phylum.DeclFlags)],
15+
extra:[(Unidoc.Shoot, TreeMapper.Flags?)] = [])
1616
{
1717
self.articles = articles
18-
self.procs = procs
1918
self.types = types
19+
self.extra = extra
2020
}
2121
}
2222
}
2323
extension Unidoc.Linker.TreeMembers:ExpressibleByArrayLiteral
2424
{
2525
init(arrayLiteral:Never...)
2626
{
27-
self.init(articles: [], procs: [], types: [:])
27+
self.init(articles: [], types: [:], extra: [])
2828
}
2929
}

TypeScript/Sources/AnySymbol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export type ModularSymbol = {
22
module: string;
3+
weight: number;
34
keywords: string[];
45
display: string;
56
uri: string;

TypeScript/Sources/NounMapCulture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface NounMapCulture {
22
c: string;
3-
n: { s: string, h: number }[];
3+
n: { s: string, h: number, f?: number }[];
44
}

TypeScript/Sources/SearchRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class SearchRunner {
2020
for (let i = 0; i < symbols.length; i++) {
2121
const symbol: AnySymbol = symbols[i];
2222
if ('module' in symbol) {
23-
this.add({ i: i, mwords: symbol.keywords });
23+
this.add({ i: i, mwords: symbol.keywords }, { boost: symbol.weight });
2424
} else {
25-
this.add({ i: i, pwords: symbol.keywords });
25+
this.add({ i: i, pwords: symbol.keywords }, { boost: 10 });
2626
}
2727
}
2828
});

TypeScript/Sources/Searchbar.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ export class Searchbar {
100100
.replaceAll(' ', '/')
101101
.toLowerCase();
102102

103+
var weight: number = 10;
104+
if (noun.f == 0) {
105+
// Symbol is deprecated.
106+
weight = 5;
107+
} else if (noun.f == 1) {
108+
// Symbol is @_spi.
109+
weight = 1;
110+
}
111+
103112
const stem: string[] = noun.s.split(/\s+/);
104113

105114
symbols.push({
106115
module: module,
116+
weight: weight,
107117
keywords: stem,
108118
display: stem.slice(1).join('.'),
109119
uri: uri

0 commit comments

Comments
 (0)