mirror of https://github.com/jlelse/GoBlog
Use posts_fts table just to get the result paths
This commit is contained in:
parent
3c38ec62dc
commit
7623ca6f70
|
@ -1,3 +1,3 @@
|
|||
create view view_posts_with_title as select id, path, title, content, published, updated, blog, section from (select p.rowid as id, p.path as path, pp.value as title, content, published, updated, blog, section from posts p left outer join post_parameters pp on p.path = pp.path where pp.parameter = 'title');
|
||||
create virtual table posts_fts using fts5(path unindexed, title, content, published unindexed, updated unindexed, blog unindexed, section unindexed, content=view_posts_with_title, content_rowid=id);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
|
@ -1,3 +1,3 @@
|
|||
drop view view_posts_with_title;
|
||||
create view view_posts_with_title as select id, path, title, content, published, updated, blog, section from (select p.rowid as id, p.path as path, pp.value as title, content, published, updated, blog, section from posts p left outer join (select * from post_parameters where parameter = 'title') pp on p.path = pp.path);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
|
@ -4,4 +4,4 @@ drop view view_posts_with_title;
|
|||
drop table posts_fts;
|
||||
create view view_posts_with_title as select id, path, title, content, published, updated, blog, section, status from (select p.rowid as id, p.path as path, pp.value as title, content, published, updated, blog, section, status from posts p left outer join post_parameters pp on p.path = pp.path where pp.parameter = 'title');
|
||||
create virtual table posts_fts using fts5(path unindexed, title, content, published unindexed, updated unindexed, blog unindexed, section unindexed, status unindexed, content=view_posts_with_title, content_rowid=id);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
|
@ -1,3 +1,3 @@
|
|||
drop view view_posts_with_title;
|
||||
create view view_posts_with_title as select p.rowid as id, p.path as path, coalesce(pp.value, '') as title, content, published, updated, blog, section, status from posts p left outer join (select * from post_parameters pp where pp.parameter = 'title') pp on p.path = pp.path;
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
|
@ -11,7 +11,7 @@ alter table posts_new rename to posts;
|
|||
create view view_posts_with_title as select p.rowid as id, p.path as path, coalesce(pp.value, '') as title, content, published, updated, blog, section, status, priority from posts p left outer join (select * from post_parameters pp where pp.parameter = 'title') pp on p.path = pp.path;
|
||||
drop table posts_fts;
|
||||
create virtual table posts_fts using fts5(path unindexed, title, content, published unindexed, updated unindexed, blog unindexed, section unindexed, status unindexed, priority unindexed, content=view_posts_with_title, content_rowid=id);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
||||
create index index_posts_status on posts (status);
|
||||
create index index_posts_blog on posts (blog);
|
||||
create index index_posts_section on posts (section);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
update posts set published = toutc(published), updated = toutc(updated);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
||||
-- insert into posts_fts(posts_fts) values ('rebuild');
|
|
@ -0,0 +1,5 @@
|
|||
drop table posts_fts;
|
||||
drop view view_posts_with_title;
|
||||
create view posts_fts_view as select p.rowid as id, p.path as path, coalesce(pp.value, '') as title, p.content as content from posts p left outer join (select * from post_parameters pp where pp.parameter = 'title') pp on p.path = pp.path;
|
||||
create virtual table posts_fts using fts5(path unindexed, title, content, content=posts_fts_view, content_rowid=id);
|
||||
insert into posts_fts(posts_fts) values ('rebuild');
|
2
main.go
2
main.go
|
@ -89,7 +89,7 @@ func main() {
|
|||
// Execute pre-start hooks
|
||||
app.preStartHooks()
|
||||
|
||||
// Initialize database and markdown
|
||||
// Initialize database
|
||||
if err = app.initDatabase(true); err != nil {
|
||||
app.logErrAndQuit("Failed to init database:", err.Error())
|
||||
return
|
||||
|
|
|
@ -16,6 +16,10 @@ import (
|
|||
)
|
||||
|
||||
func (a *goBlog) initMarkdown() {
|
||||
if a.md != nil && a.absoluteMd != nil && a.titleMd != nil {
|
||||
// Already initialized
|
||||
return
|
||||
}
|
||||
defaultGoldmarkOptions := []goldmark.Option{
|
||||
goldmark.WithRendererOptions(
|
||||
html.WithUnsafe(),
|
||||
|
|
|
@ -291,7 +291,7 @@ func buildPostsQuery(c *postsRequestConfig, selection string) (query string, arg
|
|||
queryBuilder.WriteString(" from ")
|
||||
// Table
|
||||
if c.search != "" {
|
||||
queryBuilder.WriteString("posts_fts(@search)")
|
||||
queryBuilder.WriteString("(select p.* from posts_fts(@search) ps, posts p where ps.path = p.path)")
|
||||
args = append(args, sql.Named("search", c.search))
|
||||
} else {
|
||||
queryBuilder.WriteString("posts")
|
||||
|
|
Loading…
Reference in New Issue