Which strategies do you choose when searching something?
Tags: showdev, search, cli, go
Published: 2018-11-07 17:37:31

---
title: Which strategies do you choose when searching something?
published: true
description: define your own search strategy.
tags: 
- showdev
- search
- cli
- golang
---
One of the most thing we do on the internet is searching for something, everyone has their own "strategy" when they want to search. In my case it's:

1. Search on Google :))
2. Check for answer in the first page's result, if not move to the second page.
3. Check for answer in the second page's result.
4. If I still don't found any useful answer in second page of Google search's result, move to Bing and do the same thing I did in Google search.
5. If still not found, move to another search engine such as Yandex, Ask, Duckduckgo,...

Of course, everyone (maybe by region) has their own favorite search engine. Due to that is your favorite search engine, it works really well and suits with your task. But in some cases, it may not. Because it's search engine for everybody, so in some cases, the returned value is not the result you want but the most common result.

For example, I tried to search about `yasuhiro matsumoto` (@mattn - one of my idol on Github) but it returned `yukihiro matsumoto` (ruby's creator) at the first rank of results.

![](https://thepracticaldev.s3.amazonaws.com/i/nklmjxrtqoz0871ltpve.png)

When I tried on Bing, the result are worse.

![](https://thepracticaldev.s3.amazonaws.com/i/nwoljxq4wjymy9q1zcyz.png)

And the return from Ask seems better but still does not give what I want at first rank.

![](https://thepracticaldev.s3.amazonaws.com/i/fb7kw5aeue0whqewc07h.png)

So I add a simple filter: pull all the other search engine's results and merge it by my defined rule (for example, get all cross matched urls - urls that appeared on two or more search engine's results would be a trusted urls).

![](https://thepracticaldev.s3.amazonaws.com/i/hbgbehcwcxv6vy2w7aib.png)

I created a simple program implement above idea, it's called `Boogeyman` - a console application (I'm a fan of cli tool). Source code on [github](https://github.com/khanhtc1202/boogeyman) and binary executable file available [here](https://github.com/khanhtc1202/boogeyman#download).

All strategies are defined in `domain/ranker.go`. For now, there're 3 strategies:
1. Top: Return top result of each search engines.
2. Cross Matching: Return matched results cross through multi search engines. (Appeared in 2 or more search engines)
3. All (with limit 20): Return all urls from search engines.

Feel free to implement your owned search strategy or just add new collector for collecting results from your favorite search engine. 

The new collector must implement `Collector` interface 

```golang
// file: adapter/persistent/service/collector.go
type Collector interface {
	GetSearchEngineType() domain.SearchEngineType
	Query(keyword domain.Keyword) (*domain.SearchEngine, error)
}
```

Below is the result of searching with `yasuhiro matsumoto` keyword on Boogeyman under cross match strategy.

![](https://thepracticaldev.s3.amazonaws.com/i/v74gul60223kn2j0kko2.png)

Have fun with Boogeyman :))