Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aling go version and bleve dependecy to v2.4.4 #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ An example app using [bleve](http://github.com/blevesearch/bleve) to index beers

Recommended:

```
```bash
go build
./beer-search
```

Alternative:

```
```bash
go run main.go http_util.go mapping.go
```
35 changes: 32 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
module github.com/blevesearch/beer-search

go 1.13
go 1.21

require (
github.com/blevesearch/bleve/v2 v2.0.0
github.com/gorilla/mux v1.7.4
github.com/blevesearch/bleve/v2 v2.4.4
github.com/gorilla/mux v1.8.0
)

require (
github.com/RoaringBitmap/roaring v1.9.3 // indirect
github.com/bits-and-blooms/bitset v1.12.0 // indirect
github.com/blevesearch/bleve_index_api v1.1.12 // indirect
github.com/blevesearch/geo v0.1.20 // indirect
github.com/blevesearch/go-faiss v1.0.24 // indirect
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
github.com/blevesearch/gtreap v0.1.1 // indirect
github.com/blevesearch/mmap-go v1.0.4 // indirect
github.com/blevesearch/scorch_segment_api/v2 v2.2.16 // indirect
github.com/blevesearch/segment v0.9.1 // indirect
github.com/blevesearch/snowballstem v0.9.0 // indirect
github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect
github.com/blevesearch/vellum v1.0.10 // indirect
github.com/blevesearch/zapx/v11 v11.3.10 // indirect
github.com/blevesearch/zapx/v12 v12.3.10 // indirect
github.com/blevesearch/zapx/v13 v13.3.10 // indirect
github.com/blevesearch/zapx/v14 v14.3.10 // indirect
github.com/blevesearch/zapx/v15 v15.3.16 // indirect
github.com/blevesearch/zapx/v16 v16.1.9-0.20241217210638-a0519e7caf3b // indirect
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede // indirect
github.com/mschoch/smat v0.2.0 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/sys v0.13.0 // indirect
)
164 changes: 55 additions & 109 deletions go.sum

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions http_util.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main

import (
Expand Down Expand Up @@ -34,7 +36,7 @@ func staticFileRouter() *mux.Router {
http.FileServer(http.Dir(*staticPath))))
}

r.Handle("/", http.RedirectHandler("/static/index.html", 302))
r.Handle("/", http.RedirectHandler("/static/index.html", http.StatusFound))

return r
}
Expand Down
55 changes: 37 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@ import (
"encoding/json"
_ "expvar"
"flag"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"strings"
"time"

"github.com/blevesearch/bleve/v2"
bleveHttp "github.com/blevesearch/bleve/v2/http"
)

var batchSize = flag.Int("batchSize", 100, "batch size for indexing")
var bindAddr = flag.String("addr", ":8094", "http listen address")
var jsonDir = flag.String("jsonDir", "data/", "json directory")
var indexPath = flag.String("index", "beer-search.bleve", "index path")
var staticEtag = flag.String("staticEtag", "", "A static etag value.")
var staticPath = flag.String("static", "static/", "Path to the static content")
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write mem profile to file")
var (
batchSize = flag.Int("batchSize", 100, "batch size for indexing")
bindAddr = flag.String("addr", ":8094", "http listen address")
jsonDir = flag.String("jsonDir", "data/", "json directory")
indexPath = flag.String("index", "beer-search.bleve", "index path")
staticEtag = flag.String("staticEtag", "", "A static etag value.")
staticPath = flag.String("static", "static/", "Path to the static content")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
memprofile = flag.String("memprofile", "", "write mem profile to file")
)

func main() {

flag.Parse()

log.Printf("GOMAXPROCS: %d", runtime.GOMAXPROCS(-1))
Expand All @@ -46,7 +47,10 @@ func main() {
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)

if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal(err)
}
}

// open the index
Expand Down Expand Up @@ -75,7 +79,11 @@ func main() {
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)

if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal(err)
}

f.Close()
}
}()
Expand All @@ -101,15 +109,23 @@ func main() {

// start the HTTP server
http.Handle("/", router)
log.Printf("Listening on %v", *bindAddr)
log.Fatal(http.ListenAndServe(*bindAddr, nil))

address := strings.Split(*bindAddr, ":")
host := address[0]
port := address[1]

if host == "" {
host = "localhost"
}

log.Printf("Listening on http://%v:%v", host, port)

log.Fatal(http.ListenAndServe(*bindAddr, nil))
}

func indexBeer(i bleve.Index) error {

// open the directory
dirEntries, err := ioutil.ReadDir(*jsonDir)
dirEntries, err := os.ReadDir(*jsonDir)
if err != nil {
return err
}
Expand All @@ -123,7 +139,7 @@ func indexBeer(i bleve.Index) error {
for _, dirEntry := range dirEntries {
filename := dirEntry.Name()
// read the bytes
jsonBytes, err := ioutil.ReadFile(*jsonDir + "/" + filename)
jsonBytes, err := os.ReadFile(*jsonDir + "/" + filename)
if err != nil {
return err
}
Expand All @@ -135,7 +151,10 @@ func indexBeer(i bleve.Index) error {
}
ext := filepath.Ext(filename)
docID := filename[:(len(filename) - len(ext))]
batch.Index(docID, jsonDoc)
if err := batch.Index(docID, jsonDoc); err != nil {
return err
}

batchCount++

if batchCount >= *batchSize {
Expand Down
27 changes: 13 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -34,7 +33,7 @@ func TestBeerSearchAll(t *testing.T) {
defer index.Close()

// open the directory
dirEntries, err := ioutil.ReadDir("data/")
dirEntries, err := os.ReadDir("data/")
if err != nil {
t.Fatal(err)
}
Expand All @@ -45,7 +44,7 @@ func TestBeerSearchAll(t *testing.T) {
for _, dirEntry := range dirEntries {
filename := dirEntry.Name()
// read the bytes
jsonBytes, err := ioutil.ReadFile("data/" + filename)
jsonBytes, err := os.ReadFile("data/" + filename)
if err != nil {
t.Fatal(err)
}
Expand All @@ -57,7 +56,10 @@ func TestBeerSearchAll(t *testing.T) {
}
ext := filepath.Ext(filename)
docId := filename[:(len(filename) - len(ext))]
batch.Index(docId, jsonDoc)
if err := batch.Index(docId, jsonDoc); err != nil {
t.Fatal(err)
}

batchCount++

if batchCount >= indexBatchSize {
Expand Down Expand Up @@ -200,11 +202,6 @@ func TestBeerSearchAll(t *testing.T) {
}
}

type jsonFile struct {
filename string
contents []byte
}

// this test reproduces bug #87
// https://github.com/blevesearch/bleve/issues/87
// because of which, it will deadlock
Expand All @@ -224,20 +221,22 @@ func TestBeerSearchBug87(t *testing.T) {
// start indexing documents in the background
go func() {
// open the directory
dirEntries, err := ioutil.ReadDir("data/")
dirEntries, err := os.ReadDir("data/")
if err != nil {
t.Fatal(err)
t.Error(err)
}

for _, dirEntry := range dirEntries {
filename := dirEntry.Name()
jsonBytes, err := ioutil.ReadFile("data/" + filename)
jsonBytes, err := os.ReadFile("data/" + filename)
if err != nil {
t.Fatal(err)
t.Error(err)
}
ext := filepath.Ext(filename)
docId := filename[:(len(filename) - len(ext))]
index.Index(docId, jsonBytes)
if err := index.Index(docId, jsonBytes); err != nil {
t.Error(err)
}
}
}()

Expand Down
5 changes: 2 additions & 3 deletions mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

// +build !example1
// +build !example2
//go:build !example1 && !example2
// +build !example1,!example2

package main

Expand All @@ -20,7 +20,6 @@ import (
)

func buildIndexMapping() (mapping.IndexMapping, error) {

// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName
Expand Down
2 changes: 1 addition & 1 deletion mapping_example1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

//go:build example1
// +build example1

package main
Expand All @@ -26,7 +27,6 @@ import (
const textFieldAnalyzer = "en"

func buildIndexMapping() (mapping.IndexMapping, error) {

// a custom field definition that uses our custom analyzer
notTooLongFieldMapping := bleve.NewTextFieldMapping()
notTooLongFieldMapping.Analyzer = "enNotTooLong"
Expand Down
3 changes: 2 additions & 1 deletion mapping_example2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

//go:build example2
// +build example2

package main

import (
"github.com/blevesearch/bleve/v2"
"github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
"github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
"github.com/blevesearch/bleve/v2/analysis/lang/en"
Expand All @@ -24,7 +26,6 @@ import (
const textFieldAnalyzer = "en"

func buildIndexMapping() (mapping.IndexMapping, error) {

// a custom field definition that uses our custom analyzer
edgeNgram325FieldMapping := bleve.NewTextFieldMapping()
edgeNgram325FieldMapping.Analyzer = "enWithEdgeNgram325"
Expand Down