Browse Source

Use posts_fts table just to get the result paths

master
Jan-Lukas Else 3 weeks ago
parent
commit
7623ca6f70
  1. 2
      dbmigrations/00004.sql
  2. 2
      dbmigrations/00005.sql
  3. 2
      dbmigrations/00009.sql
  4. 2
      dbmigrations/00015.sql
  5. 2
      dbmigrations/00017.sql
  6. 2
      dbmigrations/00019.sql
  7. 5
      dbmigrations/00023.sql
  8. 2
      main.go
  9. 4
      markdown.go
  10. 2
      postsDb.go

2
dbmigrations/00004.sql

@ -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');

2
dbmigrations/00005.sql

@ -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');

2
dbmigrations/00009.sql

@ -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');

2
dbmigrations/00015.sql

@ -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');

2
dbmigrations/00017.sql

@ -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);

2
dbmigrations/00019.sql

@ -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');

5
dbmigrations/00023.sql

@ -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

@ -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

4
markdown.go

@ -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(),

2
postsDb.go

@ -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…
Cancel
Save