예제 #1
0
파일: http.go 프로젝트: chop-dbhi/bitindex
		http.HandleFunc("/query", func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("content-type", "application/json")

			// Expected up to 4 keys, one for each operator.
			q := query{}

			defer r.Body.Close()

			if err := json.NewDecoder(r.Body).Decode(&q); err != nil {
				w.WriteHeader(StatusUnprocessableEntity)
				fmt.Fprint(w, err)
				return
			}

			res, err := idx.Query(q.Any, q.All, q.Nany, q.Nall)

			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				fmt.Fprint(w, err)
				return
			}

			var (
				smallest   bool
				complement bool
				items      []uint32
			)

			if q.Smallest {
				smallest = true
예제 #2
0
파일: query.go 프로젝트: chop-dbhi/bitindex
		if err != nil {
			cmd.Println("Error opening file:", err)
			os.Exit(1)
		}

		var idx *bitindex.Index

		if idx, err = bitindex.LoadIndex(f); err != nil {
			cmd.Println("Error loading index file:", err)
			os.Exit(1)
		}

		// Query time.
		t0 := time.Now()

		res, err := idx.Query(any, all, nany, nall)

		if err != nil {
			cmd.Println("Error with query:", err)
			os.Exit(1)
		}

		var (
			comp  bool
			items []uint32
		)

		thres := viper.GetFloat64("main.smallest-threshold")

		if viper.GetBool("query.complement") || viper.GetBool("query.smallest") && !res.Smallest(float32(thres)) {
			comp = true