Skip to content

Commit

Permalink
open search compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Oct 30, 2023
1 parent 8e2d46b commit 283b13b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
6 changes: 1 addition & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ The following options can be added to [Override].
# Tasks
- Finish this doc.go file.
- JS-DOS 6.22 https://js-dos.com/6.22/examples/?arkanoid
- https://js-dos.com/index_6.22.html
- Make JS-DOS only work with MS-DOS platforms.
- (long) group/releaser pages should have a link to the end of the document.
- history on the domain, Registered: 9th April 1998 [25 years, 6 months, 19 days back] previously used .com and .org.
- database on start fixes, replace empty cells with NULL.
# Mobile fixes
Expand All @@ -90,7 +86,7 @@ The following options can be added to [Override].
# Bugs
- `public/text/osd.xml` needs updating to use current search links.
-
# New features to deliver
Expand Down
13 changes: 4 additions & 9 deletions handler/app/render_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ func SearchDesc(z *zap.SugaredLogger, c echo.Context) error {
return nil
}

// PostDescriptions is the handler for the Search for file descriptions form post page.
func PostDescriptions(z *zap.SugaredLogger, c echo.Context) error {
return PostDesc(z, c, Descriptions)
}

// PostDesc is the handler for the Search for filenames form post page.
func PostDesc(z *zap.SugaredLogger, c echo.Context, mode FileSearch) error {
// PostDesc is the handler for the Search for file descriptions form post page.
func PostDesc(z *zap.SugaredLogger, c echo.Context, input string) error {
const name = "files"
ctx := context.Background()
db, err := postgres.ConnectDB()
Expand All @@ -57,15 +52,15 @@ func PostDesc(z *zap.SugaredLogger, c echo.Context, mode FileSearch) error {
}
defer db.Close()

input := c.FormValue("search-term-query")
//input := c.FormValue("search-term-query")
terms := helper.SearchTerm(input)
rel := model.Files{}

fs, _ := rel.SearchDescription(ctx, db, terms)
if err != nil {
return DatabaseErr(z, c, name, err)
}
d := mode.postStats(ctx, db, terms)
d := Descriptions.postStats(ctx, db, terms)
s := strings.Join(terms, ", ")
data := emptyFiles()
data["title"] = "Title and description results"
Expand Down
15 changes: 10 additions & 5 deletions handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"embed"
"fmt"
"net/http"
"strings"

"github.com/Defacto2/releaser"
"github.com/Defacto2/server/handler/app"
Expand Down Expand Up @@ -151,16 +152,23 @@ func (conf Configuration) Routes(z *zap.SugaredLogger, e *echo.Echo, public embe
return app.SearchDesc(z, c)
})
e.POST("/search/desc", func(c echo.Context) error {
return app.PostDescriptions(z, c)
return app.PostDesc(z, c, c.FormValue("search-term-query"))
})
e.GET("/search/releaser", func(c echo.Context) error {
return app.SearchReleaser(z, c)
})
e.POST("/search/releaser", func(c echo.Context) error {
return app.PostReleaser(z, c)
})
e.GET("/search/result", func(c echo.Context) error {
// this legacy get result should be kept for (osx.xml) opensearch compatibility
// and to keep possible backwards compatibility with third party site links.
terms := strings.ReplaceAll(c.QueryParam("query"), "+", " ") // AND replacement
terms = strings.ReplaceAll(terms, "|", ",") // OR replacement
return app.PostDesc(z, c, terms)
})
e.GET("/sum/:id", func(c echo.Context) error {
return app.Checksum(z, c, c.Param("id"))
return app.Checksum(z, c, c.Param("query"))
})
e.GET("/thanks", func(c echo.Context) error {
return app.Thanks(z, c)
Expand Down Expand Up @@ -326,9 +334,6 @@ func (c Configuration) Moved(z *zap.SugaredLogger, e *echo.Echo) (*echo.Echo, er
e.GET("/person/list/writers", func(c echo.Context) error {
return c.Redirect(code, "/writer")
})
e.GET("/search/result", func(c echo.Context) error {
return c.Redirect(code, "/search/")
})
e.GET("/upload", func(c echo.Context) error {
return c.Redirect(code, "/")
})
Expand Down
21 changes: 9 additions & 12 deletions public/text/osd.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Defacto2</ShortName>
<Description>Site wide search of the organizations, authors, web links and hosted files metadata served on Defacto2.</Description>
<Url type="application/opensearchdescription+xml"
rel="self"
template="https://defacto2.net/osd.xml" />
<Url type="text/html"
rel="results"
template="https://defacto2.net/search/result?query={searchTerms}"/>
<LongName>Defacto2 filename, group, person, word or a phrase lookup.</LongName>
<Description>Search Defacto2 for historical articles, files and digital artefacts on The Scene, underground and online.</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image height="192" width="192" type="image/png">https://defacto2.net/image/layout/favicon-192x192.png</Image>
<Image height="16" width="16" type="image/x-icon">https://defacto2.net/favicon.ico</Image>
<Query role="example" searchTerms="class" />
<Query role="example" searchTerms="razor|rzr" />
<Query role="example" searchTerms="park central bbs" />
<Url type="application/opensearchdescription+xml" rel="self" template="https://defacto2.net/osd.xml" />
<Url type="text/html" rel="results" template="https://defacto2.net/search/result?query={searchTerms}" />
<LongName>Search tiltes and descriptions.</LongName>
<Query role="example" searchTerms="hello world" />
<Query role="example" searchTerms="hello,world" />
<Attribution>
Search data is licensed under Creative Commons Attribution 4.0 International
</Attribution>
Expand Down
2 changes: 1 addition & 1 deletion view/app/searchList.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</h5>
<p class="card-text">
<form class="row g-3" method="post">
<input class="form-control form-control" list="datalistOptions" id="relDataList" name="releaser-data-list" placeholder="Type to search for a releaser...">
<input class="form-control" list="datalistOptions" id="relDataList" name="releaser-data-list" placeholder="Type to search for a releaser...">
<datalist id="datalistOptions">
{{- range $index, $name := index . "releasers"}}
<option value="{{$name}}">{{- end}}
Expand Down
2 changes: 1 addition & 1 deletion view/app/searchPost.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</h5>
<p class="card-text">
<form class="row g-3" method="post">
<input class="form-control form-control" id="relDataList" name="search-term-query" placeholder="Type in the search terms...">
<input class="form-control" id="relDataList" name="search-term-query" placeholder="Type in the search terms...">
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<button type="submit" class="btn btn-primary me-md-3">Submit</button>
<button type="reset" class="btn btn-outline-dark">Clear</button>
Expand Down

0 comments on commit 283b13b

Please sign in to comment.