flushPost writes ix.post to a new temporary file and clears the slice.
()
| 255 | // flushPost writes ix.post to a new temporary file and |
| 256 | // clears the slice. |
| 257 | func (ix *IndexWriter) flushPost() { |
| 258 | w, err := ioutil.TempFile("", "csearch-index") |
| 259 | if err != nil { |
| 260 | log.Fatal(err) |
| 261 | } |
| 262 | if ix.Verbose { |
| 263 | log.Printf("flush %d entries to %s", len(ix.post), w.Name()) |
| 264 | } |
| 265 | sortPost(ix.post) |
| 266 | |
| 267 | // Write the raw ix.post array to disk as is. |
| 268 | // This process is the one reading it back in, so byte order is not a concern. |
| 269 | data := (*[npost * 8]byte)(unsafe.Pointer(&ix.post[0]))[:len(ix.post)*8] |
| 270 | if n, err := w.Write(data); err != nil || n < len(data) { |
| 271 | if err != nil { |
| 272 | log.Fatal(err) |
| 273 | } |
| 274 | log.Fatalf("short write writing %s", w.Name()) |
| 275 | } |
| 276 | |
| 277 | ix.post = ix.post[:0] |
| 278 | w.Seek(0, 0) |
| 279 | ix.postFile = append(ix.postFile, w) |
| 280 | } |
| 281 | |
| 282 | // mergePost reads the flushed index entries and merges them |
| 283 | // into posting lists, writing the resulting lists to out. |