on main help sign in
add sigil search
commit8458711f8f1e235ba818cc337fbfe8f3988a7f5e authorJohn Hyde <johnhydefour@gmail.com> dateTue 27 Sep 2022, 16:04 (4 years ago) parent5598f67
9 files changed+118−30
desk/app/astrolabe.hoon+20−7 desk/lib/astrolabe.hoon+9 desk/lib/search.hoon+47−5 ui/src/components/search/SearchResults.svelte+4−3 ui/src/components/search/sigil/SigilInput.svelte+2−2 ui/src/components/search/sigil/Symbol.svelte+1−1 ui/src/lib/api.ts+1−1 ui/src/lib/sigil.ts+31−8 ui/src/routes/Home.svelte+3−3
desk/app/astrolabe.hoon+20−7
@@ -67,13 +67,15 @@
6767 =/ =ship `@p`(slav %p &3.path)
6868 =/ arg ?~(t.t.t.t.path %all i.t.t.t.t.path)
6969 ``astrolabe-point-set+!>((get-spawned-points:hc ship arg))
70− [%x %search @ ?(~ [%narrow ~])]
71− =/ =search-text (trip &3.path)
70+ [%x %search %patp @ ?(~ [%narrow ~])]
71+ =/ =search-text (trip &4.path)
7272 ?~ search-text ~|(%search-predicted-too-broad !!)
73− ~& "search text"
74− ~& search-text
7573 =/ expand-search =(t.t.t.path ~)
76− ``astrolabe-point-set+!>((search-opoints:hc search-text expand-search))
74+ ``astrolabe-point-set+!>((search-opoints-patp:hc search-text expand-search))
75+ [%x %search %sigil @ ~]
76+ =/ =search-text (trip &4.path)
77+ ?~ search-text ~|(%search-predicted-too-broad !!)
78+ ``astrolabe-point-set+!>((search-opoints-sigil:hc search-text))
7779 [%x %peers ~]
7880 =/ peers .^((map ship ?(%alien %known)) %ax (scrio:hc %$ /peers))
7981 ``astrolabe-point-set+!>((turn ~(tap in peers) head))
@@ -265,14 +267,25 @@
265267 |= [agg=@ud [spawn=ship *]]
266268 +(agg)
267269::
268−++ search-opoints
270+++ search-opoints-patp
269271 |= [=search-text expand-search=?]
270272 ^- (list ship)
271273 =/ search-fulls
272274 ?: expand-search
273275 (search-text-to-fulls search-text)
274276 ~[(search-text-to-full search-text)]
275− :: ~& (turn search-fulls |=(=search-full search-syls.search-full))
277+ (search-opoints search-fulls)
278+::
279+++ search-opoints-sigil
280+ |= [=search-text]
281+ ^- (list ship)
282+ =/ search-fulls
283+ ~[(sigil-search-text-to-full search-text)]
284+ (search-opoints search-fulls)
285+::
286+++ search-opoints
287+ |= [search-fulls=(list search-full)]
288+ ^- (list ship)
276289 =/ mr-searches (maybe-reverse-searches search-fulls 1.000)
277290 :: ~& (turn mr-searches |=(=mr-search pain.mr-search))
278291 :: ~& mr-searches
desk/lib/astrolabe.hoon+9
@@ -54,6 +54,15 @@
5454 .= linear-star-release:contracts:azimuth
5555 address.owner.own.p
5656::
57+++ split
58+ |* [nedl=(list) hstk=(list)]
59+ |- ^- (list _hstk)
60+ =/ brk (find nedl hstk)
61+ ?~ brk ~[hstk]
62+ =/ next (add u.brk (lent nedl))
63+ :- (scag u.brk hstk)
64+ $(hstk (slag next hstk))
65+::
5766++ smel
5867 |%
5968 ++ ship
desk/lib/search.hoon+47−5
@@ -12,7 +12,7 @@
1212++ prefixes ^~ (trip-syls sis:po)
1313++ suffixes ^~ (trip-syls dex:po)
1414++ full-opts ^~ (gulf .~zod .~fes)
15−++ galaxies ^~ `(list @p)``(list @)`full-opts
15+++ galaxies ^~ `(list @p)`full-opts
1616++ sanitize-search-text
1717 |= =search-text
1818 ^- tape
@@ -129,6 +129,25 @@
129129 ?: =(~[~ ~ ~ ~] search-opts.full)
130130 ~
131131 (some full)
132+::
133+++ sigil-search-text-to-full
134+ |= text=tape
135+ ^- search-full
136+ :- ~
137+ ^- search-opts
138+ %- flop
139+ %+ turn
140+ (split "_" text)
141+ |= ints-tape=tape
142+ ^- search-syl-opts
143+ ?: =(ints-tape "any")
144+ full-opts
145+ %+ turn
146+ (split "." ints-tape)
147+ |= =tape
148+ ~& tape
149+ `@q`(slav %ud (crip tape))
150+::
132151++ reverse-list :: that is, put first 2 in back "abcd" -> "cdab"
133152 |* lst=(list)
134153 ^- _lst
@@ -221,7 +240,10 @@
221240 |= [=syl cand=@]
222241 :: todo check cand < 256
223242 (tape-matches tape.syl (trip (tosd cand pfsf.syl)))
224−++ matches-search
243+++ syl-opts-match
244+ |= [opts=search-syl-opts cand=@]
245+ !=(~ (find ~[cand] opts))
246+++ matches-search-syls
225247 |= [search=search-syls cand-atom=@]
226248 =/ cand (rip 3 cand-atom)
227249 |-
@@ -240,6 +262,28 @@
240262 $(search t.search, cand t.cand)
241263 ==
242264::
265+++ matches-search-opts
266+ |= [search=search-opts cand-atom=@]
267+ =/ cand (rip 3 cand-atom)
268+ |-
269+ ^- ?
270+ ?~ search =(cand ~)
271+ ?~ cand
272+ ?& (syl-opts-match i.search 0)
273+ $(search t.search)
274+ ==
275+ :: =/ nncand ^- (lest @)
276+ :: ?~ cand ~[0] cand
277+ ?& (syl-opts-match i.search i.cand)
278+ $(search t.search, cand t.cand)
279+ ==
280+::
281+++ matches-search
282+ |= [search=search-full cand-atom=@]
283+ ?~ search-syls.search
284+ (matches-search-opts search-opts.search cand-atom)
285+ (matches-search-syls search-syls.search cand-atom)
286+::
243287++ opts-in-range
244288 |= [lb=@ rb=@ opts=(list @)]
245289 ^- search-syl-opts
@@ -282,8 +326,6 @@
282326 |* [agg=mold search=search-full points=opoints =page-info]
283327 |= [res=[count=@ =agg] f=$-([agg @q] agg)]
284328 ^- [count=@ =agg]
285− =/ s-syls search-syls.search
286− :: ~& s-syls
287329 =/ s-opts search-opts.search
288330 =+ [llb=.~zod rrb=`@q`(sub (bex 32) 1)]
289331 :: =< +
@@ -302,7 +344,7 @@
302344 =/ right-view (range-contains-search rlb rrb s-opts)
303345 =? res contains.left-view
304346 $(points l.points, rrb lrb, s-opts opts.left-view)
305− =? res (matches-search s-syls n)
347+ =? res (matches-search search n)
306348 =/ fits (fits-on-page count.res page-info)
307349 =. count.res +(count.res)
308350 =? agg.res fits (f agg.res n)
ui/src/components/search/SearchResults.svelte+4−3
@@ -10,7 +10,7 @@
1010
1111 export let regexQuery: RegExp;
1212 export let sigilQuery: SigilQuery;
13− export let search: string;
13+ export let patpSearch: string;
1414 export let searchMode: ('patp' | 'sigil') = 'patp';
1515 // export let patp: string;
1616 let combinedSearchResults = [];
@@ -40,7 +40,7 @@
4040 // clearTimeout(otherTimer);
4141 // if (searchMode === 'sigil') {
4242 // otherTimer = setTimeout(() => {
43− // searchedContacts.search(regexQuery, searchMode);
43+ // searchedContacts.patpSearch(regexQuery, searchMode);
4444 // }, 1000);
4545 // }
4646 // }
@@ -64,7 +64,8 @@
6464 }
6565 });
6666 }
67− $: [search, sigilQuery], doSearch();
67+ $: search = (searchMode === 'sigil') ? sigilQuery.string : patpSearch;
68+ $: [search], doSearch();
6869
6970 $: {
7071 const contactSearchResults: Rolodex = JSON.parse(JSON.stringify($searchedContacts));
ui/src/components/search/sigil/SigilInput.svelte+2−2
@@ -16,7 +16,7 @@ import { sigil } from '@tlon/sigil-js';
1616
1717 // let symbols: SymbolQuery = [];
1818
19− $: gridClasses = (sigilQuery.clan === 'galaxy' ? 'max-w-[10rem] grid items-center' : 'grid grid-cols-2 items-center');
19+ $: gridClasses = (sigilQuery.clan === 'galaxy' ? 'max-w-[10rem] grid items-center' : 'max-w-[18rem] grid grid-cols-2 items-center');
2020
2121 function unfocusSymbol() {
2222 focusedSymbolIndex = undefined;
@@ -42,7 +42,7 @@ import { sigil } from '@tlon/sigil-js';
4242 <ClanSelect bind:clan={sigilQuery.clan} />
4343 <div class="flex flex-col xs:flex-row">
4444 <div class="grow-[2] w-full xs:m-0 xs:max-w-[18rem]" on:click={unfocusSymbol}>
45− <div class="max-w-[18rem] min-h-[14rem] mx-auto p-4 {gridClasses} xs:rounded-bl-2xl">
45+ <div class="min-h-[14rem] mx-auto p-4 {gridClasses} xs:rounded-bl-2xl">
4646 {#each sigilQuery.activeSymbols as symbol, index}
4747 <SymbolInput
4848 bind:symbolQuery={symbol}
ui/src/components/search/sigil/Symbol.svelte+1−1
@@ -9,7 +9,7 @@
99 export let fgColor: string = 'black';
1010 export let bgColor: string = 'white';
1111 export let altBgColor: string = undefined;
12− export let hoverColor: string = 'blue';
12+ export let hoverColor: string = '#8f8';
1313 export let opacity: number = 1;
1414 export let inverted: boolean = false;
1515 export let interactive: boolean = false;
ui/src/lib/api.ts+1−1
@@ -27,7 +27,7 @@ export function getPeers(): Promise<any> {
2727}
2828
2929export async function searchPoints(search: string, mode: ('patp' | 'sigil')): Promise<Patp[]> {
30− const { points } = await scry<any>(`/search/${search}`);
30+ const { points } = await scry<any>(`/search/${mode}/${search}`);
3131 return points.map(normalizeId);
3232}
3333
ui/src/lib/sigil.ts+31−8
@@ -33,9 +33,10 @@ export class SigilQuery {
3333 this.symbols.forEach((symbol, i) => {
3434 if (i % 2 === 0) {
3535 symbol.symbolType = 'prefix';
36+ // symbol.components = ['gci', 'lhf'];
3637 } else {
3738 symbol.symbolType = 'suffix';
38− // symbol.components = ['gsq', 'ablf2']
39+ // symbol.components = ['gsq', 'atrf4'];
3940 }
4041 });
4142 this.symbols = this.symbols;
@@ -50,13 +51,17 @@ export class SigilQuery {
5051 }
5152
5253 get isPlausible() {
53− return this.activeSymbols.every(symbol => !symbol.isPlausible);
54+ return this.activeSymbols.every(symbol => symbol.isPlausible);
5455 }
5556
5657 get querySyls(): string[][] {
5758 return this.activeSymbols.map(symbol => symbol.plausibleSyllables);
5859 }
5960
61+ get queryInts(): number[][] {
62+ return this.activeSymbols.map(symbol => symbol.plausibleInts);
63+ }
64+
6065 get isDefinitive() {
6166 return this.querySyls.every(syls => syls.length === 1);
6267 }
@@ -65,8 +70,14 @@ export class SigilQuery {
6570 return this.activeSymbols.some(symbol => symbol.components.length > 0);
6671 }
6772
73+ get isWorthSearching() {
74+ if (!this.isNotEmpty) return false; // 🙃
75+ if (!this.isPlausible) return false;
76+ return 100000 > this.querySyls.reduce((acc, syls) => acc * (syls.length || 256), 1);
77+ }
78+
6879 get string(): string {
69− return this.symbols.map((symbol) => symbol.components.join(',')).join('|')
80+ return this.queryInts.map((int) => int.length == 256 ? 'any' : int.join('.')).join('_');
7081 }
7182
7283 setSymbol(symbol: SymbolQuery, activeSymbolIndex: number) {
@@ -92,15 +103,18 @@ function addEquivalentParts(parts: string[]): string[] {
92103 return [...parts, ...moreParts];
93104}
94105
95−export function getPlausibleSyllables(parts: string[], symbolType: SymbolType): string[] {
96− let plausibleSyllables: string[];
106+function getSyllablesBySymbolType(symbolType: SymbolType): string[] {
97107 if (symbolType === 'prefix') {
98− plausibleSyllables = prefixes;
108+ return prefixes;
99109 } else if (symbolType === 'suffix') {
100− plausibleSyllables = suffixes;
110+ return suffixes;
101111 } else {
102− plausibleSyllables = [...prefixes, ...suffixes];
112+ return [...prefixes, ...suffixes];
103113 }
114+}
115+
116+export function getPlausibleSyllables(parts: string[], symbolType: SymbolType): string[] {
117+ let plausibleSyllables = getSyllablesBySymbolType(symbolType);
104118 const possibilitiesByPart = parts.map((partId) => {
105119 let parents = partParents[partId];
106120 const otherPart = equivalentParts[partId];
@@ -113,6 +127,11 @@ export function getPlausibleSyllables(parts: string[], symbolType: SymbolType):
113127 return plausibleSyllables;
114128}
115129
130+function convertSyllableToInt(syl: string, symbolType: SymbolType): number {
131+ let syls = getSyllablesBySymbolType(symbolType);
132+ return syls.findIndex(s => s === syl) % 256;
133+}
134+
116135export function getPlausibleNewParts(parts: string[], symbolType: SymbolType): string[] {
117136 const syllables: string[] = getPlausibleSyllables(parts, symbolType);
118137 let plausibleParts = uniq(syllables.map((syllable) => symbolDefs[syllable]).flat());
@@ -205,6 +224,10 @@ export class SymbolQuery {
205224 return getPlausibleSyllables(this.components, this.symbolType);
206225 }
207226
227+ get plausibleInts() {
228+ return this.plausibleSyllables.map(syl => convertSyllableToInt(syl, this.symbolType));
229+ }
230+
208231 get isPlausible() {
209232 return this.plausibleSyllables.length > 0;
210233 }
ui/src/routes/Home.svelte+3−3
@@ -146,9 +146,9 @@
146146 <StarChart patp={analysis.patpIsValid ? analysis.patp : null} />
147147 {:else if analysis.patpIsValid}
148148 <ShipView patp={analysis.patp} />
149− {:else if (searchMode === 'patp' && analysis.queryIsValid) || (searchMode == 'sigil' && sigilQuery.isNotEmpty)}
150− <SearchResults regexQuery={analysis.query} sigilQuery={sigilQuery} search={analysis.search}
151− {searchMode} />
149+ {:else if (searchMode === 'patp' && analysis.queryIsValid) || (searchMode == 'sigil' && sigilQuery.isWorthSearching)}
150+ <SearchResults regexQuery={analysis.query} sigilQuery={sigilQuery}
151+ patpSearch={analysis.search} {searchMode} />
152152 {:else if (analysis.search.length > 0)}
153153 <ValidationProblems problems={analysis.queryProblems} />
154154 {:else}