### Index a Document in Bluge Source: https://github.com/blugelabs/bluge/blob/master/README.md This Go code snippet demonstrates the process of initializing a Bluge writer, creating a new document with a specified ID and a text field, and then updating the index with this document. It includes essential error handling and ensures the writer is properly closed using a defer statement. ```go config := bluge.DefaultConfig(path) writer, err := bluge.OpenWriter(config) if err != nil { log.Fatalf("error opening writer: %v", err) } defer writer.Close() doc := bluge.NewDocument("example"). AddField(bluge.NewTextField("name", "bluge")) err = writer.Update(doc.ID(), doc) if err != nil { log.Fatalf("error updating document: %v", err) } ``` -------------------------------- ### Query Documents in Bluge Source: https://github.com/blugelabs/bluge/blob/master/README.md This Go code snippet illustrates how to perform a search query using Bluge. It involves obtaining an index reader, constructing a match query for a specific field, executing a search request with standard aggregations, and then iterating through the document matches to extract and print the stored field values, specifically the document ID. Robust error handling is included for each step of the querying process. ```go reader, err := writer.Reader() if err != nil { log.Fatalf("error getting index reader: %v", err) } defer reader.Close() query := bluge.NewMatchQuery("bluge").SetField("name") request := bluge.NewTopNSearch(10, query). WithStandardAggregations() documentMatchIterator, err := reader.Search(context.Background(), request) if err != nil { log.Fatalf("error executing search: %v", err) } match, err := documentMatchIterator.Next() for err == nil && match != nil { err = match.VisitStoredFields(func(field string, value []byte) bool { if field == "_id" { fmt.Printf("match: %s\n", string(value)) } return true }) if err != nil { log.Fatalf("error loading stored fields: %v", err) } match, err = documentMatchIterator.Next() } if err != nil { log.Fatalf("error iterator document matches: %v", err) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.