violet
1.0.0
__ ___ ___
/ | / | |__ |
/ | __/ |___ |___ |
一個簡單的Go搜尋引擎。
go get -u github.com/cosmtrek/violet
# dont forget add `violet` environment variable
# vi ~/.bash_profile
export violet='$GOPATH/src/github.com/cosmtrek/violet'
violet 有兩種模式,一種適合像我這樣喜歡終端的人,另一種是作為 http 伺服器運作。
violet -path=INDEX_PATH -index=INDEX_NAME -fields=INDEX_FIELDS -data=DATA_FILE -query=true -server=false
然後你就可以搜尋你輸入的任何內容。
# start server
violet
伺服器啟動後,開啟另一個終端機發出post請求建立索引。
# first create a json file post.json
{
"index": "INDEX_NAME",
"index_path": "INDEX_PATH",
"fields": "INDEX_FIELDS",
"datafile": "DATA_FILE"
}
# then create index
curl -XPOST -d @./data/tweets.json "http://localhost:6060/index"
# try to query
curl "http://localhost:6000/INDEX_NAME/search?query=TERM"
為了有效率地進行搜索,需要有條件地進行查詢。目前僅支援以下形式:
word
搜尋單字word1 word2
搜尋多個單字word1 -word2
搜尋 word1 並排除 word2field1:word1 field2:word2
在field1中搜尋word1,在field2中搜尋word2word field>10
搜尋單字且欄位(整數)大於10 推文搜尋
它搜尋我儲存在./data/tweets
中的推文。