From f0dbe295d7d4f8282c2bde86bc4387b367bef589 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 3 Mar 2017 19:57:20 +0100 Subject: added a first strus search to the site --- build.sh | 4 +- config.toml | 8 +- content/search/_index.md | 0 static/css/localstyle.css | 16 +- strus/README | 23 + strus/create_xml.sh | 50 + strus/document.ana | 25 + themes/new_theme/layouts/_default/list.html | 7 +- themes/new_theme/layouts/index/single.html | 0 themes/new_theme/layouts/partials/ranklist.html | 218 + themes/new_theme/layouts/partials/sidebar.html | 2 +- .../partials/widgets/google_site_search.html | 12 + .../new_theme/layouts/partials/widgets/search.html | 12 - .../layouts/partials/widgets/strus_search.html | 21 + themes/new_theme/static/js/jquery.js | 9789 ++++++++++++++++++++ themes/new_theme/static/js/url-search-params.js | 2 + 16 files changed, 10168 insertions(+), 21 deletions(-) create mode 100644 content/search/_index.md create mode 100644 strus/README create mode 100755 strus/create_xml.sh create mode 100644 strus/document.ana create mode 100644 themes/new_theme/layouts/index/single.html create mode 100644 themes/new_theme/layouts/partials/ranklist.html create mode 100644 themes/new_theme/layouts/partials/widgets/google_site_search.html delete mode 100644 themes/new_theme/layouts/partials/widgets/search.html create mode 100644 themes/new_theme/layouts/partials/widgets/strus_search.html create mode 100644 themes/new_theme/static/js/jquery.js create mode 100644 themes/new_theme/static/js/url-search-params.js diff --git a/build.sh b/build.sh index 99dfb5c..8ccec62 100755 --- a/build.sh +++ b/build.sh @@ -2,4 +2,6 @@ rm -rf public ~/go/bin/hugo -v -b http://www.andreasbaumann.cc - +sed -i 's@http://eeepc.lan:8080/strus/query/wwwandreasbaumanncc@http://www.andreasbaumann.cc/strus/query/wwwandreasbaumanncc@g' \ + public/search/index.html + diff --git a/config.toml b/config.toml index 83c45c0..24d081f 100644 --- a/config.toml +++ b/config.toml @@ -61,7 +61,13 @@ category = "categories" url = "/blog" [[menu.main]] - name = "Contact" + name = "Search" weight = 90 + identifier = "search" + url = "/search" + +[[menu.main]] + name = "Contact" + weight = 100 identifier = "contact" url = "/contact" diff --git a/content/search/_index.md b/content/search/_index.md new file mode 100644 index 0000000..e69de29 diff --git a/static/css/localstyle.css b/static/css/localstyle.css index 397d2b5..e0c3b5a 100644 --- a/static/css/localstyle.css +++ b/static/css/localstyle.css @@ -1,4 +1,12 @@ -img[alt=Email] { width: 20px; height: 20px; } -img[alt=Skype] { width: 20px; height: 20px; } -img[alt=Twitter] { width: 20px; height: 20px; } -img[alt=Github] { width: 20px; height: 20px; } +img[alt=Email], +img[alt=Skype], +img[alt=Twitter], +img[alt=Github] { + width: 20px; height: 20px; +} + +#ranklist table, +#ranklist th, +#ranklist td { + border: none; +} diff --git a/strus/README b/strus/README new file mode 100644 index 0000000..d503c0c --- /dev/null +++ b/strus/README @@ -0,0 +1,23 @@ +# Search index with strus + +# For now create an XML from the content, later have a directory iterator +# over 'content' and read TOML/YAML headers and markdown... + +# TODO: this becomes obsolete with a Hugo segmenter which undestands +# YAML/TOML/JSON and Markdown: +# remarshal (https://github.com/dbohdan/remarshal) +# pandoc (http://pandoc.org/) + +./create_xml.sh > posts.xml + +xmllint -noout posts.xml + +# Create the strus search index: + +rm -rf storage +mkdir storage +strusCreate -s 'path=storage/wwwandreasbaumanncc; metadata=doclen UINT16, publish_date UINT16' + +strusAnalyze document.ana posts.xml |& less + +strusInsert -c 1000 -f 1 -t 1 -s "path=storage/wwwandreasbaumanncc" document.ana posts.xml diff --git a/strus/create_xml.sh b/strus/create_xml.sh new file mode 100755 index 0000000..fa7ddd6 --- /dev/null +++ b/strus/create_xml.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +cat < + +EOF + +for file in `find ../content/ -name '*.md'`; do + echo "$file.." 1>&2 + slug=`echo $file | sed 's@../content@@g' | sed 's@/_index.md$@@g' | sed 's@.md$@@g'` + if test "x$slug" = "x"; then + slug="/" + fi + + awk 'BEGIN { i = 0 } /\+\+\+/{x="F"++i;}{print > x;}' $file >/dev/null 2>&1 + + if test ! -f F1 -a -f F2; then + continue + fi + + tail -n +2 F1 > meta.toml + tail -n +3 F2 > body.md + + sed -i 's/\&/&/g' meta.toml + sed -i 's//\>/g' meta.toml + sed -i 's/\&/&/g' body.md + sed -i 's//\>/g' body.md + + remarshal -if toml -of json meta.toml > meta.json + pandoc -f markdown -t docbook body.md > body.xml + + echo "" + echo "$slug" + echo "$file" + echo "" + cat meta.json + echo "" + echo "" + cat body.xml + echo "" + echo "" + + rm -f meta.* body.* F1 F2 +done + +cat < +EOF diff --git a/strus/document.ana b/strus/document.ana new file mode 100644 index 0000000..a296775 --- /dev/null +++ b/strus/document.ana @@ -0,0 +1,25 @@ +[Attribute] + docid = orig content /posts/post/slug(); + filename = orig content /posts/post/filename(); +# title = orig content /posts/post/meta()/title(); + +[Content] + "encoding=UTF-8; content=JSON;" /posts/post/meta(); + +[SearchIndex] +# word = lc:convdia(en):stem(en):lc word /posts/post/body/para(); +# word = orig split /posts/post/body/para(); + word = lc regex("([A-Za-z']+)") /posts/post/body/para(); + +[ForwardIndex] + word = orig split /posts/post/body/para(); + +[Document] + post = /posts/post; + +#[MetaData] +# release_date = date2int("d 1877-01-01", "%Y-%m-%d %H:%M:%s *") content /posts/post/meta()/date; + +[Aggregator] + doclen = count( word ); + diff --git a/themes/new_theme/layouts/_default/list.html b/themes/new_theme/layouts/_default/list.html index 0f5e063..82f03fc 100644 --- a/themes/new_theme/layouts/_default/list.html +++ b/themes/new_theme/layouts/_default/list.html @@ -9,7 +9,11 @@

{{ .Title }}

- {{ .Content }} + {{ if ( eq $section "search" ) }} + {{ partial "ranklist.html" . }} + {{ else }} + {{ .Content }} + {{ end }}
@@ -56,7 +60,6 @@ {{ partial "pagination.html" . }} - {{ end }} {{ partial "sidebar.html" . }} diff --git a/themes/new_theme/layouts/index/single.html b/themes/new_theme/layouts/index/single.html new file mode 100644 index 0000000..e69de29 diff --git a/themes/new_theme/layouts/partials/ranklist.html b/themes/new_theme/layouts/partials/ranklist.html new file mode 100644 index 0000000..29027bc --- /dev/null +++ b/themes/new_theme/layouts/partials/ranklist.html @@ -0,0 +1,218 @@ + + + +
+
diff --git a/themes/new_theme/layouts/partials/sidebar.html b/themes/new_theme/layouts/partials/sidebar.html index b621bb2..123c544 100644 --- a/themes/new_theme/layouts/partials/sidebar.html +++ b/themes/new_theme/layouts/partials/sidebar.html @@ -1,5 +1,5 @@