<commit_before>package solr

import (
	"fmt"
	"net/url"
	"strings"
)

type CoreAdmin struct {
	url      *url.URL
	username string
	password string
}

type CoreAdminResponse struct {
	// Quick access to responseHeader.status
	Status int
	// Raw response from solr core admin
	Result map[string]interface{}
}

// solrUrl should look like this http://0.0.0.0:8983/solr[/admin/cores] ie /admin/cores will append automatically
// when calling Action
func NewCoreAdmin(solrUrl string) (*CoreAdmin, error) {
	u, err := url.ParseRequestURI(solrUrl)
	if err != nil {
		return nil, err
	}

	return &CoreAdmin{url: u}, nil
}

// Set basic auth in case solr require login
func (ca *CoreAdmin) SetBasicAuth(username, password string) {
	ca.username = username
	ca.password = password
}

// Call to admin/cores endpoint, additional params neccessary for this action can specified in params.
// No check is done for those params so check https://wiki.apache.org/solr/CoreAdmin for detail
func (ca *CoreAdmin) Action(action string, params *url.Values) (*CoreAdminResponse, error) {
	switch strings.ToUpper(action) {
	case "STATUS":
		params.Set("action", "STATUS")
	case "RELOAD":
		params.Set("action", "RELOAD")
	case "CREATE":
		params.Set("action", "CREATE")
	case "RENAME":
		params.Set("action", "RENAME")
	case "SWAP":
		params.Set("action", "SWAP")
	case "UNLOAD":
		params.Set("action", "UNLOAD")
	case "SPLIT":
		params.Set("action", "SPLIT")
	case "MERGEINDEXES":
		params.Set("action", "mergeindexes")
	default:
		return nil, fmt.Errorf("Action '%s' not supported", action)
	}

	params.Set("wt", "json")

	r, err := HTTPGet(fmt.Sprintf("%s/admin/cores?%s", ca.url.String(), params.Encode()), nil, ca.username, ca.password)
	if err != nil {
		return nil, err
	}
	resp, err := bytes2json(&r)
	if err != nil {
		return nil, err
	}
	result := &CoreAdminResponse{Result: resp}
	result.Status = int(resp["responseHeader"].(map[string]interface{})["status"].(float64))
	return result, nil
}

// pass empty string as core if you want status of all cores.
// See https://wiki.apache.org/solr/CoreAdmin#STATUS
func (ca *CoreAdmin) Status(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}

	if core != "" {
		params.Add("core", core)
	}

	return ca.Action("STATUS", params)
}

// Swap one core with other core.
// See https://wiki.apache.org/solr/CoreAdmin#SWAP
func (ca *CoreAdmin) Swap(core, other string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	params.Add("other", other)
	return ca.Action("SWAP", params)
}

// Reload a core, see https://wiki.apache.org/solr/CoreAdmin#RELOAD
func (ca *CoreAdmin) Reload(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	return ca.Action("RELOAD", params)
}

// Unload a core, see https://wiki.apache.org/solr/CoreAdmin#UNLOAD
// If you want to use those flag deleteIndex, deleteDataDir, deleteInstanceDir
// Please use Action-method with those params specified, like ca.Action("UNLOAD", params)
func (ca *CoreAdmin) Unload(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	return ca.Action("UNLOAD", params)
}

// Rename a core
// See https://wiki.apache.org/solr/CoreAdmin#RENAME
func (ca *CoreAdmin) Rename(core, other string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	params.Add("other", other)
	return ca.Action("RENAME", params)
}

// Split a core into 2 or more cores
// See https://wiki.apache.org/solr/CoreAdmin#SPLIT
// Only targetCore is supported here. If you want to use "path"
// use Action method
func (ca *CoreAdmin) Split(core string, targetCore ...string) (*CoreAdminResponse, error) {
	if len(targetCore) < 2 {
		return nil, fmt.Errorf("You must specify at least 2 target cores")
	}
	params := &url.Values{}
	params.Add("core", core)
	for _, target := range targetCore {
		params.Add("targetCore", target)
	}
	return ca.Action("SPLIT", params)
}<commit_msg>Corrected docstring and version info<commit_after>package solr

import (
	"fmt"
	"net/url"
	"strings"
)

type CoreAdmin struct {
	url      *url.URL
	username string
	password string
}

type CoreAdminResponse struct {
	// Quick access to responseHeader.status
	Status int
	// Raw response from solr core admin
	Result map[string]interface{}
}

// solrUrl should look like this http://0.0.0.0:8983/solr[/admin/cores] ie /admin/cores will append automatically
// when calling Action
func NewCoreAdmin(solrUrl string) (*CoreAdmin, error) {
	u, err := url.ParseRequestURI(solrUrl)
	if err != nil {
		return nil, err
	}

	return &CoreAdmin{url: u}, nil
}

// Set basic auth in case solr require login
func (ca *CoreAdmin) SetBasicAuth(username, password string) {
	ca.username = username
	ca.password = password
}

// Call to admin/cores endpoint, additional params neccessary for this action can specified in params.
// No check is done for those params so check https://wiki.apache.org/solr/CoreAdmin for detail
func (ca *CoreAdmin) Action(action string, params *url.Values) (*CoreAdminResponse, error) {
	switch strings.ToUpper(action) {
	case "STATUS":
		params.Set("action", "STATUS")
	case "RELOAD":
		params.Set("action", "RELOAD")
	case "CREATE":
		params.Set("action", "CREATE")
	case "RENAME":
		params.Set("action", "RENAME")
	case "SWAP":
		params.Set("action", "SWAP")
	case "UNLOAD":
		params.Set("action", "UNLOAD")
	case "SPLIT":
		params.Set("action", "SPLIT")
	case "MERGEINDEXES":
		params.Set("action", "mergeindexes")
	default:
		return nil, fmt.Errorf("Action '%s' not supported", action)
	}

	params.Set("wt", "json")

	r, err := HTTPGet(fmt.Sprintf("%s/admin/cores?%s", ca.url.String(), params.Encode()), nil, ca.username, ca.password)
	if err != nil {
		return nil, err
	}
	resp, err := bytes2json(&r)
	if err != nil {
		return nil, err
	}
	result := &CoreAdminResponse{Result: resp}
	result.Status = int(resp["responseHeader"].(map[string]interface{})["status"].(float64))
	return result, nil
}

// pass empty string as core if you want status of all cores.
// See https://wiki.apache.org/solr/CoreAdmin#STATUS
func (ca *CoreAdmin) Status(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}

	if core != "" {
		params.Add("core", core)
	}

	return ca.Action("STATUS", params)
}

// Swap one core with other core.
// See https://wiki.apache.org/solr/CoreAdmin#SWAP
func (ca *CoreAdmin) Swap(core, other string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	params.Add("other", other)
	return ca.Action("SWAP", params)
}

// Reload a core, see https://wiki.apache.org/solr/CoreAdmin#RELOAD
func (ca *CoreAdmin) Reload(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	return ca.Action("RELOAD", params)
}

// Unload a core, see https://wiki.apache.org/solr/CoreAdmin#UNLOAD
// If you want to use those flag deleteIndex, deleteDataDir, deleteInstanceDir
// Please use Action-method with those params specified, like ca.Action("UNLOAD", params)
func (ca *CoreAdmin) Unload(core string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	return ca.Action("UNLOAD", params)
}

// Rename a core
// See https://wiki.apache.org/solr/CoreAdmin#RENAME
func (ca *CoreAdmin) Rename(core, other string) (*CoreAdminResponse, error) {
	params := &url.Values{}
	params.Add("core", core)
	params.Add("other", other)
	return ca.Action("RENAME", params)
}

// Splits an index into two or more indexes
// See https://wiki.apache.org/solr/CoreAdmin#SPLIT
// Only targetCore is supported here. If you want to use "path"
// use Action method. Available in Solr4.3
func (ca *CoreAdmin) Split(core string, targetCore ...string) (*CoreAdminResponse, error) {
	if len(targetCore) < 2 {
		return nil, fmt.Errorf("You must specify at least 2 target cores")
	}
	params := &url.Values{}
	params.Add("core", core)
	for _, target := range targetCore {
		params.Add("targetCore", target)
	}
	return ca.Action("SPLIT", params)
}
{'fraction_non_alphanumeric': 0.15221723966118586, 'fraction_numerical': 0.0036123567513702045, 'mean_word_length': 4.43234100135318, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6674478', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2658, 'n_words': 779}