Beispiel #1
0
func (u *User) openMessageLog() {
	var err error

	u.messageLog, err = bolt.Open(path.Join(appDir, "logs", u.UUID+"_log"), 0600, nil)
	if err != nil {
		log.Fatal(err)
	}

	u.messageLog.Update(func(tx *bolt.Tx) error {
		tx.CreateBucketIfNotExists(bucketMessages)

		return nil
	})

	indexPath := path.Join(appDir, "logs", u.UUID+"_index")
	u.messageIndex, err = bleve.Open(indexPath)
	if err == bleve.ErrorIndexPathDoesNotExist {
		mapping := bleve.NewIndexMapping()
		u.messageIndex, err = bleve.New(indexPath, mapping)
		if err != nil {
			log.Fatal(err)
		}
	} else if err != nil {
		log.Fatal(err)
	}
}
Beispiel #2
0
func main() {

	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		err = pprof.StartCPUProfile(f)
		if err != nil {
			log.Fatal(err)
		}
		defer pprof.StopCPUProfile()
	}

	if *indexPath == "" {
		log.Fatal("Specify index to query")
	}

	if flag.NArg() < 1 {
		log.Fatal("Specify search query")
	}

	// open index
	index, err := bleve.Open(*indexPath)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		cerr := index.Close()
		if cerr != nil {
			log.Fatalf("error closing index: %v", err)
		}
	}()

	for i := 0; i < *repeat; i++ {
		// build a search with the provided parameters
		queryString := strings.Join(flag.Args(), " ")
		query := bleve.NewQueryStringQuery(queryString)
		searchRequest := bleve.NewSearchRequestOptions(query, *limit, *skip, *explain)

		// enable highlights if requested
		if *includeHighlights {
			searchRequest.Highlight = bleve.NewHighlightWithStyle("ansi")
		}

		// execute the search
		searchResult, err := index.Search(searchRequest)
		if err != nil {
			log.Fatalf("search error: %v", err)
		}
		fmt.Println(searchResult)
	}
}
Beispiel #3
0
func main() {
	flag.Parse()
	if *indexPath == "" {
		log.Fatal("specify index to dump")
	}

	index, err := bleve.Open(*indexPath)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		cerr := index.Close()
		if cerr != nil {
			log.Fatalf("error closing index: %v", err)
		}
	}()

	if *mappingOnly {
		mapping := index.Mapping()
		jsonBytes, err := json.MarshalIndent(mapping, "", "  ")
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s\n", jsonBytes)
		return
	}

	var dumpChan chan interface{}
	if *docID != "" {
		dumpChan = index.DumpDoc(*docID)
	} else if *fieldsOnly {
		dumpChan = index.DumpFields()
	} else {
		dumpChan = index.DumpAll()
	}

	for rowOrErr := range dumpChan {
		switch rowOrErr := rowOrErr.(type) {
		case error:
			log.Printf("error dumping: %v", rowOrErr)
		case upside_down.UpsideDownCouchRow:
			fmt.Printf("%v\n", rowOrErr)
			fmt.Printf("Key:   % -100x\nValue: % -100x\n\n", rowOrErr.Key(), rowOrErr.Value())
		}
	}
}
Beispiel #4
0
func main() {

	flag.Parse()

	if *indexPath == "" {
		log.Fatal("must specify index path")
	}

	// open the index
	index, err := bleve.Open(*indexPath)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		cerr := index.Close()
		if cerr != nil {
			log.Fatalf("error closing index: %v", err)
		}
	}()

	if flag.NArg() < 1 {
		log.Fatal("must specify at least one path to index")
	}

	for file := range handleArgs(flag.Args()) {
		// index the files
		docID := file.filename
		if !*keepDir {
			_, docID = filepath.Split(docID)
		}
		if !*keepExt {
			ext := filepath.Ext(docID)
			docID = docID[0 : len(docID)-len(ext)]
		}
		log.Printf("Indexing: %s", docID)
		err = index.Index(docID, file.contents)
		if err != nil {
			log.Fatal(err)
		}
	}
}
Beispiel #5
0
func main() {

	flag.Parse()

	if *indexPath == "" {
		log.Fatal("must specify index path")
	}

	// open the index
	index, err := bleve.Open(*indexPath)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		cerr := index.Close()
		if cerr != nil {
			log.Fatalf("error closing index: %v", err)
		}
	}()

	if flag.NArg() < 1 {
		log.Fatal("must specify at least one path to index")
	}

	i := 0
	batch := index.NewBatch()

	for _, file := range flag.Args() {

		file, err := os.Open(file)
		defer func() {
			cerr := file.Close()
			if cerr != nil {
				log.Fatalf("error closing file: %v", cerr)
			}
		}()
		if err != nil {
			log.Fatal(err)
		}

		log.Printf("Indexing: %s\n", file.Name())
		r := bufio.NewReader(file)

		for {
			if i%*batchSize == 0 {
				log.Printf("Indexing batch (%d docs)...\n", i)
				err := index.Batch(batch)
				if err != nil {
					log.Fatal(err)
				}
				batch = index.NewBatch()
			}

			b, _ := r.ReadBytes('\n')
			if len(b) == 0 {
				break
			}
			docID := randomString(5)
			err := batch.Index(docID, b)
			if err != nil {
				log.Fatal(err)
			}
			i++
		}
		err = index.Batch(batch)
		if err != nil {
			log.Fatal(err)
		}
	}
}