![]() |
Photo: Jason Mrachina (CC BY-NC-ND 2.0) |
Blogger is a database that lets you shuffle and filter posts in different ways.
Today we take that to the next level, with logical OR searches on labels A or B (posts with any of the labels).
This is a sequel to the simpler logical AND search: only posts with both labels A and B.
Label Search OR
myblog.blogspot.com/search/?q=label:label1|label:label2
(You can use more than two search terms.)
Note that syntax: q=, then label:, then the label name, separated from the next by the | character.
In this case, | means "or."
That is the "pipe" or vertical bar. On many Western keyboards it is the uppercase right-leaning slash (\).
If you have trouble finding it, you can use its hexadecimal code instead: %7C.
It might look garbled (/?q=label:label1%7Clabel:label2
) but will work in your browser bar.
Update: As a reader describes in his comment below, one can also use written-word versions of the these operators ("OR" "NOT" "AND").
However, they are case-sensitive and must be separated from the search terms by spaces.
Although the AND search I described previously is a label-search page that uses the "/search/label/" form, this OR search is a general search, though one restricted to labels.
Here is OR in action:
too-clever-by-half.blogspot.com/search/?q=label:feeds|label:"things that
changed"
That's all posts with either label (or both).
![]() |
Image: Kismalac (public domain) |
A OR B |
Defined as any posts about feeds or things that changed, or both, together on one page.
Oh yeah. Those quotation marks:
If any of the search terms comprises more than one word, you'll have to put those terms in quotes.
label:"things that changed"
Pretty fussy work, but the point is that once you have constructed the url correctly (and you should test it), it's an accessible page on your blog.
You can link to it, and your readers can view the page with a single click. The page will revise itself whenever you apply or remove any of the labels involved.
That's the power of databases!
Order
/search/q=label:
" method is a true search, so if you want to
link to the search ordered by date, add this to the url:
&by-date=true
The default alternative is an undefined "by relevance" sort, if you are curious to know what Google thinks is "relevant."
Extra Credit
- You can use these methods on more than two labels at a time.
-
The "
?q=label:
" syntax also works with the "+" operator for logical AND. It's just a bit fussier than the alternative syntax. -
Without the "
label:
" qualifier, a search term finds posts that contain the word rather than the label. So, you could search for all "things that changed" posts that include the word "Picasaweb." (A word search, without the "label:
" qualifier, does not search label names.) - If you are a Boolean hotshot, you can construct links like "all posts that have the 'attitude' label and at at least one of 'tips' or 'things that changed.'"
- Update: It is also possible to exclude posts from a database search using logical not. "All posts about bread that are not also about cheese."
Links in the series
- Yes, your blog is a database.
- You can filter on multiple labels: A and B.
- You can filter things out: A but not B.
- You can similarly combine and filter blog feeds.
Adam, I'd love to tidy a set of labels on my blog but am scared as I have 427 posts. Any cautious hints before I jump in?
ReplyDelete@standby, this is really a strategic editorial decision, rather than a technical one. What sort of user experience can you facilitate by characterizing posts by topic?
DeletePut yourself in your readers' place: how can you organize posts to make it easier to go deeper into the blog and find interesting things?
Forethought like this is a good idea. However, fear should not hold you back since you can undo anything you do with labels.
The blog linked to your account only has 12 posts, so I am guessing you have another account. Since I can't see the other blog, these remarks are kind of generic.
But, I hope, helpful.
Sorry to take so long in saying THANK YOU. I hadn't realised my experimental blog was visible - now corrected. Yes, it's a much bigger blog that I'm referring to. Your assurance helps. Thanks again
ReplyDeleteI just knew about the + operator working for labels but didn't know about the remaining. This could be very useful in creating a more useful set of options for the visitors. Many thanks to you sir! 🙏
ReplyDelete@Adam , I don't know whether you have mentioned this one before or not, but just for the record, one can also use OR in capital letters instead of the | character, in the Blogger search query.
ReplyDeleteFor example, label:"some label name" OR label:"another label name" .
I see that NOT works similarly instead of -
Only difference is that when using the search operators | or - , there may or may not be any space between the search operators and its adjacent words. In case of using capital lettered words OR or NOT, there should be a space in between (like my example above).
This also works for search queries in search box. Such as, instead of cow | goat | horse you can type cow OR goat OR horse in Blogger's search box input.
(See that both cow | goat | horse and cow|goat|horse will work. That is, with or without spaces between search operators.)
(But only cow OR goat OR horse will work and cowORgoatORhorse will not work. Also, if it is or in small letters, it will not work).
Similarly for NOT and AND. But AND is the default case anyway.
Same way it is for label tags in search. One can alternatively use OR AND NOT with spaces between them and the words or between them and label:"label names".
So, in case someone has any trouble using "pipe" or vertical bar (as you mentioned in the post), or %7C, they can simply use OR, (with spaces on its both sides).
So, your example URL
---
(without encoding that is showing " and spaces)
https://too-clever-by-half.blogspot.com/search/?q=label:feeds|label:"things that changed"
(URL encoded)
https://too-clever-by-half.blogspot.com/search/?q=label:feeds%7Clabel:%22things%20that%20changed%22
can also be written as:
---
(URL encoded)
https://too-clever-by-half.blogspot.com/search/?q=label:feeds%20OR%20label:%22things%20that%20changed%22
(without encoding that is showing " and spaces)
https://too-clever-by-half.blogspot.com/search/?q=label:feeds OR label:"things that changed"
Or simply type the following in the search box and hit ENTER :
label:feeds OR label:"things that changed"
That is very good! I think I missed this because, as you point out, these written-word operators are case sensitive.
DeleteI am sure I tried it while researching this report, but I'll bet I used "or," not "OR."