In Blogger it is not possible to do some advanced search from the built-in search boxes or label/tag cloud.
I present here a workaround for this - implemented in AutoHotkey and Javascript (for my personal Chrome extension) that allows to make combined searches with multiple labels and keywords in a Blogger/blogspot Blog.
Problem description
Solution
The Url for a search with labels looks like:
Single label search: https://tdalon.blogspot.com/search/label/autohotkey
Combined label and keyword search: https://tdalon.blogspot.com/search?q=label:autohotkey+label:microsoft-teams+reaction
Blogger Quick Search AutoHotkey Implementation
Function is implemented in ahk/Lib/Blogger.ahk-> Blogger_Search
Blogger_Search(sUrl,sDefSearch:=""){
RegExMatch(sUrl,"https?://[^/]*",sRootUrl)
ReRootUrl := StrReplace(sRootUrl,".","\.")
If (sDefSearch = "") {
; Get def search from input url
If RegExMatch(sUrl,"/search/label/([^\?&]*)",sMatch) {
sDefSearch = #%sMatch1%
} Else If RegExMatch(sUrl,"\?q=([^&]*)",sDefSearch) {
sDefSearch := sDefSearch1
sPat := "label:([^\+]*)"
Pos=1
While Pos := RegExMatch(sDefSearch, sPat, tag,Pos+StrLen(tag))
sTags := sTags . " #" . tag1
sDefSearch := RegExReplace(sDefSearch,sPat,"")
sDefSearch := sTags . "+" . sDefSearch
sDefSearch := StrReplace(sDefSearch,"%20"," ")
sDefSearch := StrReplace(sDefSearch,"+"," ")
sDefSearch := Trim(sDefSearch)
}
InputBox, sSearch , Blogger Search, Enter search string (use # for tags):,,640,125,,,,,%sDefSearch%
if ErrorLevel
return
sSearch := Trim(sSearch)
}
sPat := "#([^\s]*)"
sTags =
Pos=1
While Pos := RegExMatch(sSearch, sPat, tag,Pos+StrLen(tag))
sTags := sTags . "+label:" . tag1
If Not (sTags = "") {
sTags := SubStr(sTags,2) ; remove starting +
sSearch := RegExReplace(sSearch,sPat,"")
sSearch := Trim(sSearch)
If (sSearch = "")
sSearch := sTags
Else
sSearch := sTags . "+" . sSearch
}
sSearchUrl := sRootUrl . "/search?q=" . sSearch . "&max-results=500"
;Run, %sSearchUrl%
Send ^n ; New Window
Sleep 500
Clip_Paste(sSearchUrl)
Send {Enter}
} ; eofun
NWS PowerTool Integration
This feature is implemented in the NWS PowerTool QuickSearch feature.
Simply use Win+F when viewing a Blogger post in the Browser, to trigger the Quick Search.
Chrome Extension Implementation
I have also implemented such a functionality to quickly search in my blog via the omnibar and my customed Chrome Extension.
You can view the code in this GitHub repository: https://github.com/tdalon/my_crx
I trigger this from the omnibar, typing 'm' followed by TAB to activate the specific chrome extension action. Then type the main keyword 'mb' (for my blog) followed by the string to search.
Words prefixed with # are interpreted as Labels.
Typing enter will then run the search in my blog.
No comments:
Post a Comment