New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search boosts #1930
Search boosts #1930
Changes from 10 commits
2844af7
adb740e
6870ceb
5ec06bc
84ccef0
356ab3d
aa7483f
ca60240
d9a60fc
8d2a6e5
009a244
545fc88
6a41cee
ee9b66e
aa9a272
b68ede6
735ac30
9e9af66
8864deb
d0bdf5a
26d4a9a
f30213b
54abe77
3601b26
ae839ef
d6e5b18
09d7c26
7ca811b
45bf9da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,13 @@ import { | |
DeclarationReflection, | ||
ProjectReflection, | ||
ReflectionKind, | ||
} from "../../models/reflections/index"; | ||
import { GroupPlugin } from "../../converter/plugins/GroupPlugin"; | ||
} from "../../models"; | ||
import { GroupPlugin } from "../../converter/plugins"; | ||
import { Component, RendererComponent } from "../components"; | ||
import { RendererEvent } from "../events"; | ||
import { writeFileSync } from "../../utils"; | ||
import { DefaultTheme } from "../themes/default/DefaultTheme"; | ||
import type { IDocument } from "../themes/default/assets/typedoc/components/Search"; | ||
|
||
/** | ||
* A plugin that exports an index of the project to a javascript file. | ||
|
@@ -63,12 +64,15 @@ export class JavascriptIndexPlugin extends RendererComponent { | |
parent = undefined; | ||
} | ||
|
||
const row: any = { | ||
const row: IDocument = { | ||
id: rows.length, | ||
kind: reflection.kind, | ||
name: reflection.name, | ||
url: reflection.url, | ||
classes: reflection.cssClasses, | ||
classes: reflection.cssClasses ?? "", | ||
categories: (reflection.categories ?? []).map( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this is going to greatly increase the size of the search data file, which for large projects is already pretty big... could we instead apply the category boosts in this plugin and add a Doing it this way means that this module could also theoretically emit an event with the rows before building the index, allowing third party plugins to easily hook in and change boosts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to check that this works properly with categorizeByGroup set to both true and false. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually wasn't able to get any kind of reaction out of cateogry stuff. How does one activate the category plugin in the example app? I didn't see any reference to it in in typedoc.json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The category plugin is always active - but it will only do something if the documented members use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see; I guess I didn't notice that. Would it be okay if I sprinkle a few in there to exercise some of this stuff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's controlled by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've been experimenting with that; I tried setting it to both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I add this to
(note: that does result in infinitely self-referential recursion, which is probably not a good thing) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe this is where your suggestion to encode the boost score rather than the cats themselves could come into play--I could write the numbers in the Category plugin, and dodge the crazy recursion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
(category) => category.title | ||
), | ||
}; | ||
|
||
if (parent) { | ||
|
@@ -100,7 +104,11 @@ export class JavascriptIndexPlugin extends RendererComponent { | |
"assets", | ||
"search.js" | ||
); | ||
|
||
const searchConfig = this.application.options.getValue("search"); | ||
|
||
const jsonData = JSON.stringify({ | ||
searchConfig, | ||
kinds, | ||
rows, | ||
index, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import type { LogLevel } from "../loggers"; | |
import type { SortStrategy } from "../sort"; | ||
import { isAbsolute, join, resolve } from "path"; | ||
import type { EntryPointStrategy } from "../entry-point"; | ||
import type { ReflectionKind } from "../../models/reflections/kind"; | ||
import { ReflectionKind } from "../../models/reflections/kind"; | ||
|
||
export const EmitStrategy = { | ||
true: true, // Alias for both, for backwards compatibility until 0.23 | ||
|
@@ -50,6 +50,16 @@ export type TypeDocOptionValues = { | |
: TypeDocOptionMap[K][keyof TypeDocOptionMap[K]]; | ||
}; | ||
|
||
const Kinds = Object.values(ReflectionKind); | ||
export interface SearchConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd like to split this up into a few options:
I think it makes sense to always give exact matches a large boost, probably needs experimentation to figure out what that should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (removed the numResults thing; we don't need it right now, and I don't want to needlessly prolong this review) |
||
numResults?: number; | ||
boosts?: { | ||
exactMatch?: number; | ||
byKind?: { [key: typeof Kinds[number]]: number }; | ||
byCategory?: { [key: string]: number }; | ||
}; | ||
} | ||
|
||
/** | ||
* Describes all TypeDoc options. Used internally to provide better types when fetching options. | ||
* External consumers should likely use {@link TypeDocOptions} instead. | ||
|
@@ -107,6 +117,7 @@ export interface TypeDocOptionMap { | |
version: boolean; | ||
showConfig: boolean; | ||
plugin: string[]; | ||
search: unknown; | ||
logger: unknown; // string | Function | ||
logLevel: typeof LogLevel; | ||
markedOptions: unknown; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,41 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"], | ||
"lib": [ | ||
"es2019", | ||
"es2020.promise", | ||
"es2020.bigint", | ||
"es2020.string", | ||
"dom" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't have this here. DOM stuff isn't available in Node, where we generally run, so it's a bad idea to have it for type checking. (This is why the index plugin didn't import IDocument before, I'm fine moving that so that it can be used by both projects) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still a bit confused about this. If I remove "dom" then I get build errors in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it has something to do with importing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That error is because the frontend doesn't have access to node modules, and bootstrap.ts was updated to import IDocument from a path which also ended up importing something that depended on native node modules. I'm fine just leaving the any for now, hasn't really caused any major pain. Still need to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, forgot to remove "dom". 26d4a9a I have to say I found several aspects of this project a bit confusing:
Etc. Overall, I enjoyed exploring the code. |
||
], | ||
"target": "es2019", | ||
|
||
// Add our `ts` internal types | ||
"typeRoots": ["node_modules/@types", "src/lib/types"], | ||
"types": ["node", "glob", "lunr", "marked", "minimatch", "mocha"], | ||
|
||
// Speed up dev compilation time | ||
"incremental": true, | ||
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo", | ||
|
||
"experimentalDecorators": true, | ||
|
||
"strict": true, | ||
"alwaysStrict": true, | ||
|
||
// For tests | ||
"resolveJsonModule": true, | ||
|
||
// Linting | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"importsNotUsedAsValues": "error", | ||
|
||
// Library | ||
"preserveConstEnums": true, | ||
"declaration": true, | ||
"sourceMap": true, | ||
"isolatedModules": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
|
||
// Output | ||
"outDir": "dist/", | ||
"rootDir": "src/", | ||
"newLine": "LF", | ||
|
||
"jsx": "react", | ||
"jsxFactory": "JSX.createElement", | ||
"jsxFragmentFactory": "JSX.Fragment" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to leave this as is - again looking to avoid increasing the search.js file size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, gotcha. I think I was getting some kind of build complaint somewhere, but between this and the errors I was getting from the dom stuff, maybe I have something configured wrong. I'll try to narrow it down tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because IDocument doesn't define this property as optional - it should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll touch that up, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
009a244