-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adds ability to search for templates by title/description messages. #28
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Some responses return strings and others objects. Should have consistent formatting.
let template; | ||
try { | ||
template = await templateService.getTemplateByCadenceASTHash( | ||
await genHash(cadenceAST), |
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.
You're awaiting the genHash
function multiple times for the same input. Compute it once.
@@ -0,0 +1,185 @@ | |||
import express, { Request, Response, Router } from "express"; | |||
import { body } from "express-validator"; |
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.
remove
let templateId: string = ""; | ||
let _name: string = name; | ||
while (_name !== undefined) { | ||
let foundName = namesJSONFile[_name]; |
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.
Are names guaranteed to be unique?
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.
In the names json file, yes
@JeffreyDoyle this also needs documentation on the readme or something |
try { | ||
const templates = await templateService.searchTemplates( | ||
page ?? 0, | ||
range ?? 100, |
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.
You need a max range or someone could slam it with too large a number
Vercel preview link doesn't work. Is it suppose to? |
Also, is there a library you can use to make search better? Exact text match does not seem ideal. Tagging may be a better option since search is hard. |
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.
Hey, I'm coming from this issue #18 (comment).
As I mentioned, Flowser app would benefit from this kind of functionality greatly. Exciting stuff!
Added a few thoughts of my own below.
return res.send(template); | ||
}); | ||
|
||
router.post("/templates/search/messages", async (req: Request, res: Response) => { |
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.
Nit: The endpoint path is a bit confusing to me, as it could also be interpreted as searching for a "message" resource. But that's not true, I think it's only searching by "message" fields like title/description.
Could it make more sense for it to be named /templates/search
or even just GET /templates?search={query}
(where an empty query or no query parameter present could list all templates)? Using the GET verb could also make sense (semantically at least), since this only reads data.
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 can see there is also an endpoint for searching by the AST hash. Maybe that could instead just be another query parameter like /templates/search?cadence_ast_hash
?
It could lead to simpler API if there was a single endpoint that supported different search options, as opposed to multiple endpoints, each supporting a different search option.
Another search option could be searching by "dependencies", as I mentioned here: #18 (comment)
Thoughts?
} | ||
|
||
if (searchMessagesDescriptionENUS) { | ||
queryBuilder = queryBuilder.where("messages_description_enUS", "like", `%${searchMessagesDescriptionENUS}%`) |
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.
Wondering if it would be possible to do full-text, instead of searching for exact substring matches?
I can see that SQLite does support some kind of full-text search capabilities: https://www.sqlite.org/fts5.html. But I'm not sure if this feature is available in better-sqlite3 which is used in this project.
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.
Should we update the documentation in README with v2 endpoints?
Adds ability to search for templates by title/description messages.
eg:
returns: