<commit_before>package indexer

import (
	"encoding/json"
	"golang.org/x/net/context"
	"gopkg.in/olivere/elastic.v5"
)

type Indexer struct {
	el *elastic.Client
}

type Reference struct {
	ParentHash string `json:"parent_hash"`
	Name       string `json:"name"`
}

func NewIndexer(el *elastic.Client) *Indexer {
	return &Indexer{
		el: el,
	}
}

// Add file or directory to index
func (i Indexer) IndexItem(doctype string, hash string, properties map[string]interface{}) error {
	_, err := i.el.Update().
		Index("ipfs").
		Type(doctype).
		Id(hash).
		Doc(properties).
		DocAsUpsert(true).
		Do(context.TODO())

	if err != nil {
		// Handle error
		return err
	}

	return nil
}

// Return existing references for an object, or nil, and the type
// When no object is found nil is returned but no error is set
// Otherwise, an empty list is returned
func (i Indexer) GetReferences(hash string) ([]Reference, string, error) {
	fsc := elastic.NewFetchSourceContext(true)
	fsc.Include("references")

	res, err := i.el.Get().
		Index("ipfs").Type("_all").FetchSourceContext(fsc).Id(hash).Do(context.TODO())

	if err != nil {
		if elastic.IsNotFound(err) {
			return nil, "", nil
		}
		return nil, "", err
	}

	var result map[string][]Reference
	err = json.Unmarshal(*res.Source, &result)
	if err != nil {
		return nil, "", err
	}<commit_msg>Punctuation for docs.<commit_after>package indexer

import (
	"encoding/json"
	"golang.org/x/net/context"
	"gopkg.in/olivere/elastic.v5"
)

type Indexer struct {
	el *elastic.Client
}

type Reference struct {
	ParentHash string `json:"parent_hash"`
	Name       string `json:"name"`
}

func NewIndexer(el *elastic.Client) *Indexer {
	return &Indexer{
		el: el,
	}
}

// Add file or directory to index
func (i Indexer) IndexItem(doctype string, hash string, properties map[string]interface{}) error {
	_, err := i.el.Update().
		Index("ipfs").
		Type(doctype).
		Id(hash).
		Doc(properties).
		DocAsUpsert(true).
		Do(context.TODO())

	if err != nil {
		// Handle error
		return err
	}

	return nil
}

// Return existing references for an object, or nil, and the type.
// When no object is found nil is returned but no error is set.
// Otherwise, an empty list is returned.
func (i Indexer) GetReferences(hash string) ([]Reference, string, error) {
	fsc := elastic.NewFetchSourceContext(true)
	fsc.Include("references")

	res, err := i.el.Get().
		Index("ipfs").Type("_all").FetchSourceContext(fsc).Id(hash).Do(context.TODO())

	if err != nil {
		if elastic.IsNotFound(err) {
			return nil, "", nil
		}
		return nil, "", err
	}

	var result map[string][]Reference
	err = json.Unmarshal(*res.Source, &result)
	if err != nil {
		return nil, "", err
	}
{'fraction_non_alphanumeric': 0.1461051062243757, 'fraction_numerical': 0.0007454342154304882, 'mean_word_length': 3.8014311270125223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2051403', 'n_tokens_mistral': 991, 'n_tokens_neox': 926, 'n_words': 260}