Improved search
This commit is contained in:
parent
464a6ec26b
commit
326c4161aa
@ -36,7 +36,9 @@ func updateAnimeIndex() {
|
|||||||
animeSearchIndex.TextToID[strings.ToLower(anime.Title.English)] = anime.ID
|
animeSearchIndex.TextToID[strings.ToLower(anime.Title.English)] = anime.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if anime.Title.Japanese != "" {
|
// Make sure we only include Japanese titles that actually contain unicode letters
|
||||||
|
// because otherwise they might overlap with the English titles.
|
||||||
|
if anime.Title.Japanese != "" && arn.ContainsUnicodeLetters(anime.Title.Japanese) {
|
||||||
animeSearchIndex.TextToID[strings.ToLower(anime.Title.Japanese)] = anime.ID
|
animeSearchIndex.TextToID[strings.ToLower(anime.Title.Japanese)] = anime.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
func TestRoutes(t *testing.T) {
|
func TestRoutes(t *testing.T) {
|
||||||
app := configure(aero.New())
|
app := configure(aero.New())
|
||||||
|
|
||||||
for _, examples := range tests {
|
for _, examples := range routeTests {
|
||||||
for _, example := range examples {
|
for _, example := range examples {
|
||||||
request, err := http.NewRequest("GET", example, nil)
|
request, err := http.NewRequest("GET", example, nil)
|
||||||
|
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxUsers = 9 * 7
|
const maxUsers = 9 * 4
|
||||||
const maxAnime = 9 * 7
|
const maxAnime = 9 * 4
|
||||||
|
|
||||||
// Get search page.
|
// Get search page.
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
term := ctx.Get("term")
|
term := ctx.Query("q")
|
||||||
|
|
||||||
userResults, animeResults := arn.Search(term, maxUsers, maxAnime)
|
userResults, animeResults := arn.Search(term, maxUsers, maxAnime)
|
||||||
return ctx.HTML(components.SearchResults(userResults, animeResults))
|
return ctx.HTML(components.SearchResults(userResults, animeResults))
|
||||||
|
@ -7,6 +7,7 @@ component SearchResults(users []*arn.User, animeResults []*arn.Anime)
|
|||||||
p No users found.
|
p No users found.
|
||||||
else
|
else
|
||||||
each user in users
|
each user in users
|
||||||
|
.mountable(data-mountable-type="user")
|
||||||
Avatar(user)
|
Avatar(user)
|
||||||
//- a.ajax(href=user.Link())= user.Nick
|
//- a.ajax(href=user.Link())= user.Nick
|
||||||
|
|
||||||
@ -17,5 +18,5 @@ component SearchResults(users []*arn.User, animeResults []*arn.Anime)
|
|||||||
p No anime found.
|
p No anime found.
|
||||||
else
|
else
|
||||||
each anime in animeResults
|
each anime in animeResults
|
||||||
a.profile-watching-list-item.ajax(href=anime.Link(), title=anime.Title.Canonical)
|
a.profile-watching-list-item.mountable.ajax(href=anime.Link(), title=anime.Title.Canonical, data-mountable-type="anime")
|
||||||
img.anime-cover-image.anime-search-result(src=anime.Image.Tiny, alt=anime.Title.Canonical)
|
img.anime-cover-image.anime-search-result(src=anime.Image.Tiny, alt=anime.Title.Canonical)
|
18
rewrite.go
18
rewrite.go
@ -18,10 +18,26 @@ func init() {
|
|||||||
newURI := "/user/"
|
newURI := "/user/"
|
||||||
userName := requestURI[2:]
|
userName := requestURI[2:]
|
||||||
ctx.SetURI(newURI + userName)
|
ctx.SetURI(newURI + userName)
|
||||||
} else if strings.HasPrefix(requestURI, plusRouteAjax) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(requestURI, plusRouteAjax) {
|
||||||
newURI := "/_/user/"
|
newURI := "/_/user/"
|
||||||
userName := requestURI[4:]
|
userName := requestURI[4:]
|
||||||
ctx.SetURI(newURI + userName)
|
ctx.SetURI(newURI + userName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(requestURI, "/search/") {
|
||||||
|
searchTerm := requestURI[len("/search/"):]
|
||||||
|
ctx.Request.URL.RawQuery = "q=" + searchTerm
|
||||||
|
ctx.SetURI("/search")
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(requestURI, "/_/search/") {
|
||||||
|
searchTerm := requestURI[len("/_/search/"):]
|
||||||
|
ctx.Request.URL.RawQuery = "q=" + searchTerm
|
||||||
|
ctx.SetURI("/_/search")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,10 @@ export function search(arn: AnimeNotifier, search: HTMLInputElement, e: Keyboard
|
|||||||
|
|
||||||
let term = search.value
|
let term = search.value
|
||||||
|
|
||||||
if(!window.location.pathname.startsWith("/search/")) {
|
if(window.location.pathname.startsWith("/search/")) {
|
||||||
history.pushState("search", null, "/search/" + term)
|
|
||||||
} else {
|
|
||||||
history.replaceState("search", null, "/search/" + term)
|
history.replaceState("search", null, "/search/" + term)
|
||||||
|
} else {
|
||||||
|
history.pushState("search", null, "/search/" + term)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!term || term.length < 2) {
|
if(!term || term.length < 2) {
|
||||||
@ -165,7 +165,7 @@ export function search(arn: AnimeNotifier, search: HTMLInputElement, e: Keyboard
|
|||||||
arn.app.content.appendChild(results)
|
arn.app.content.appendChild(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
arn.app.get("/_/search/" + encodeURI(term))
|
arn.app.get("/_/search/" + term)
|
||||||
.then(html => {
|
.then(html => {
|
||||||
if(!search.value) {
|
if(!search.value) {
|
||||||
return
|
return
|
||||||
|
@ -199,13 +199,23 @@ export class AnimeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifyDelayed(className: string, func: (element: HTMLElement) => void) {
|
modifyDelayed(className: string, func: (element: HTMLElement) => void) {
|
||||||
|
let mountableTypes = {
|
||||||
|
general: 0
|
||||||
|
}
|
||||||
|
|
||||||
const delay = 20
|
const delay = 20
|
||||||
const maxDelay = 500
|
const maxDelay = 1000
|
||||||
|
|
||||||
let time = 0
|
let time = 0
|
||||||
|
|
||||||
for(let element of findAll(className)) {
|
for(let element of findAll(className)) {
|
||||||
time += delay
|
let type = element.dataset.mountableType || "general"
|
||||||
|
|
||||||
|
if(type in mountableTypes) {
|
||||||
|
time = mountableTypes[element.dataset.mountableType] += delay
|
||||||
|
} else {
|
||||||
|
time = mountableTypes[element.dataset.mountableType] = 0
|
||||||
|
}
|
||||||
|
|
||||||
if(time > maxDelay) {
|
if(time > maxDelay) {
|
||||||
func(element)
|
func(element)
|
||||||
|
Loading…
Reference in New Issue
Block a user