Beispiel #1
0
func main() {
	log.Print("Oepning FSDirectory...")
	// path := "src/github.com/balzaczyy/golucene/search/testdata/win8/belfrysample"
	path := "search/testdata/win8/belfrysample"
	// path := "/private/tmp/kc/index/belfrysample"
	// path := "c:/tmp/kc/index/belfrysample"
	d, err := store.OpenFSDirectory(path)
	if err != nil {
		panic(err)
	}
	log.Print("Opening DirectoryReader...")
	r, err := index.OpenDirectoryReader(d)
	if err != nil {
		panic(err)
	}
	if r == nil {
		panic("DirectoryReader cannot be opened.")
	}
	if len(r.Leaves()) < 1 {
		panic("Should have one leaf.")
	}
	log.Print("Initializing IndexSearcher...")
	ss := search.NewIndexSearcher(r)
	log.Print("Searching...")
	n, err := ss.SearchTop(search.NewTermQuery(index.NewTerm("content", "bat")), 10)
	if err != nil {
		panic(err)
	}
	log.Print(n)
}
func TestInitTerm(t *testing.T) {
	path := "../search/testdata/win8/belfrysample"
	d, err := store.OpenFSDirectory(path)
	if err != nil {
		t.Error(err)
	}
	r, err := OpenDirectoryReader(d)
	if err != nil {
		t.Error(err)
	}
	leaves := r.Context().Leaves()
	if len(leaves) != 1 {
		t.Error("Should have one leaf.")
	}
	ctx := leaves[0]
	fields := ctx.reader.Fields()
	terms := fields.Terms("content")
	termsEnum := terms.Iterator(nil)

	if len(termsEnum.Term()) != 0 {
		t.Error("Initial term should has zero length.")
	}

	ok, err := termsEnum.SeekExact(NewTerm("content", "bat").Bytes)
	if err != nil {
		t.Error(err)
	}
	if !ok {
		t.Error("SeekExact should return true.")
	}
}
Beispiel #3
0
func TestLastCommitGeneration(t *testing.T) {
	d, err := store.OpenFSDirectory("../search/testdata/belfrysample")
	if err != nil {
		t.Error(err)
	}

	files, err := d.ListAll()
	if err != nil {
		t.Error(err)
	}
	if files != nil {
		genA := LastCommitGeneration(files)
		assertEquals(t, int64(1), genA)
	}
}
Beispiel #4
0
func TestReadFieldInfos(t *testing.T) {
	path := "../search/testdata/osx/belfrysample"
	d, err := store.OpenFSDirectory(path)
	if err != nil {
		t.Error(err)
	}
	ctx := store.NewIOContextBool(false)
	cd, err := store.NewCompoundFileDirectory(d, "_0.cfs", ctx, false)
	if err != nil {
		t.Error(err)
	}
	fis, err := Lucene42FieldInfosReader(cd, "_0", store.IO_CONTEXT_READONCE)
	if err != nil {
		t.Error(err)
	}
	if !fis.hasNorms || fis.hasDocValues {
		t.Errorf("hasNorms must be true and hasDocValues must be false, but found %v", fis)
	}
}
Beispiel #5
0
func TestLeaves(t *testing.T) {
	path := "../search/testdata/win8/belfrysample"
	d, err := store.OpenFSDirectory(path)
	if err != nil {
		t.Error(err)
	}
	r, err := OpenDirectoryReader(d)
	if err != nil {
		t.Error(err)
	}
	if len(r.Leaves()) != 1 {
		t.Error("Should have one sub reader.")
	}
	fmt.Println(r)
	r2 := r.Context().Reader()
	fmt.Println(r2)
	if len(r2.Leaves()) != 1 {
		t.Error("Should have one sub reader.")
	}
}
Beispiel #6
0
func TestLastCommitGeneration(t *testing.T) {
	d, err := store.OpenFSDirectory("testdata/belfrysample")
	if err != nil {
		t.Error(err)
	}

	files, err := d.ListAll()
	if err != nil {
		t.Error(err)
	}
	if files != nil {
		genA := index.LastCommitGeneration(files)
		if genA != 1 {
			t.Error("Should be 1, but was %v", genA)
		}
	}
	// r, err := index.OpenDirectoryReader(d)
	// if err != nil {
	// 	t.Error(err)
	// }

	// ss := NewIndexSearcher(r)
	// assertEquals(t, 8, ss.SearchTop(NewTermQuery(index.NewTerm("content", "bat")), 10))
}