Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ type OAIPMH struct {

// WebResource holds all the configuration options for the WebResource endpoint
type WebResource struct {
Enabled bool `json:"enabled"` // Make the webresource endpoint available
WebResourceDir string `json:"sourceDir"` // Target directory for the webresources
CacheResourceDir string `json:"cacheDir"` // cache directory for the webresources
enableSearch bool `json:"enableSearch"` // enable searching for images in ElasticSearch
Enabled bool `json:"enabled"` // Make the webresource endpoint available
WebResourceDir string `json:"sourceDir"` // Target directory for the webresources
CacheResourceDir string `json:"cacheDir"` // cache directory for the webresources
enableSearch bool // enable searching for images in ElasticSearch
MediaManagerHost string `json:"mediaManagerHost"` // the domain to build the derivatives
SmallDefault string `json:"smallDefault"`
MediumDefault string `json:"mediumDefault"`
Expand Down Expand Up @@ -405,7 +405,7 @@ func setDefaults() {
// sitemap
viper.SetDefault("SiteMap.Enabled", false)

// pid
// pid
viper.SetDefault("PID.enabled", false)

// ead
Expand Down
2 changes: 1 addition & 1 deletion config/config_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
12 changes: 6 additions & 6 deletions hub3/ead/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ func (c *DaoClient) PublishFindingAid(cfg *DaoConfig, excludeMetsFiles ...bool)
}

if !excludeFiles {
err = c.PublishFiles(cfg, &fa)
err = c.PublishFiles(cfg, fa)
if err != nil {
return err
}
}

fg, err := cfg.findingAidFragmentGraph(&fa)
fg, err := cfg.findingAidFragmentGraph(fa)
if err != nil {
return err
}
Expand All @@ -176,7 +176,7 @@ func (c *DaoClient) PublishFindingAid(cfg *DaoConfig, excludeMetsFiles ...bool)

if !excludeFiles {
cfg.ObjectCount = int(fa.GetFileCount())
cfg.MimeTypes = getMimeTypes(&fa)
cfg.MimeTypes = getMimeTypes(fa)
return c.dropOrphans(cfg)
}

Expand Down Expand Up @@ -497,16 +497,16 @@ func (cfg *DaoConfig) Mets() (*Cmets, error) {
return readMETS(cfg.GetMetsFilePath())
}

func (cfg *DaoConfig) FindingAid(c *DaoClient) (eadpb.FindingAid, error) {
func (cfg *DaoConfig) FindingAid(c *DaoClient) (*eadpb.FindingAid, error) {
if c.HttpFallback && !cfg.MetsFileExists() {
if err := c.StoreMets(cfg); err != nil {
return eadpb.FindingAid{}, err
return nil, err
}
}

mets, err := cfg.Mets()
if err != nil {
return eadpb.FindingAid{}, err
return nil, err
}

return mets.newFindingAid(cfg)
Expand Down
4 changes: 2 additions & 2 deletions hub3/ead/eadpb/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

// NewPager creates a new Pager with all navigation settings.
func NewPager(total int64, request *ViewRequest) (Pager, error) {
pager := Pager{
func NewPager(total int64, request *ViewRequest) (*Pager, error) {
pager := &Pager{
HasNext: false,
HasPrevious: false,
TotalCount: int32(total),
Expand Down
24 changes: 12 additions & 12 deletions hub3/ead/eadpb/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func TestNewPager(t *testing.T) {
tests := []struct {
name string
args args
want Pager
want *Pager
wantErr bool
}{
{
"no results",
args{total: 0, request: &ViewRequest{PageSize: int32(10), Page: int32(1)}},
Pager{
&Pager{
HasNext: false,
HasPrevious: false,
TotalCount: 0,
Expand All @@ -59,7 +59,7 @@ func TestNewPager(t *testing.T) {
{
"1 page results",
args{total: 3, request: &ViewRequest{PageSize: int32(10), Page: int32(1)}},
Pager{
&Pager{
HasNext: false,
HasPrevious: false,
TotalCount: 3,
Expand All @@ -77,7 +77,7 @@ func TestNewPager(t *testing.T) {
{
"first page; 2 page results; 11 hits",
args{total: 11, request: &ViewRequest{PageSize: int32(10), Page: int32(1)}},
Pager{
&Pager{
HasNext: true,
HasPrevious: false,
TotalCount: 11,
Expand All @@ -95,7 +95,7 @@ func TestNewPager(t *testing.T) {
{
"second page; 2 page results; 11 hits",
args{total: 11, request: &ViewRequest{PageSize: int32(10), Page: int32(2)}},
Pager{
&Pager{
HasNext: false,
HasPrevious: true,
TotalCount: 11,
Expand All @@ -117,7 +117,7 @@ func TestNewPager(t *testing.T) {
Page: int32(1),
SortKey: 4,
}},
Pager{
&Pager{
HasNext: false,
HasPrevious: false,
TotalCount: 10,
Expand All @@ -139,7 +139,7 @@ func TestNewPager(t *testing.T) {
Page: int32(1),
Filename: "123.jpg",
}},
Pager{
&Pager{
HasNext: false,
HasPrevious: false,
TotalCount: 10,
Expand All @@ -161,7 +161,7 @@ func TestNewPager(t *testing.T) {
Page: int32(5),
Paging: true,
}},
Pager{
&Pager{
HasNext: true,
HasPrevious: true,
TotalCount: 105,
Expand All @@ -182,7 +182,7 @@ func TestNewPager(t *testing.T) {
PageSize: int32(1),
Page: int32(5),
}},
Pager{
&Pager{
HasNext: true,
HasPrevious: true,
TotalCount: 15,
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestSetPage(t *testing.T) {
tests := []struct {
name string
args args
want Pager
want *Pager
wantErr bool
}{
{
Expand All @@ -234,7 +234,7 @@ func TestSetPage(t *testing.T) {
request: &ViewRequest{PageSize: int32(10), Page: int32(1)},
sortKey: int32(5),
},
Pager{
&Pager{
HasNext: true,
HasPrevious: false,
TotalCount: 17,
Expand All @@ -256,7 +256,7 @@ func TestSetPage(t *testing.T) {
request: &ViewRequest{PageSize: int32(10), Page: int32(1)},
sortKey: int32(15),
},
Pager{
&Pager{
HasNext: false,
HasPrevious: true,
TotalCount: 17,
Expand Down
6 changes: 3 additions & 3 deletions hub3/ead/mets.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func updateFileInfo(files map[string]*eadpb.File, fg []*CfileGrp, fa *eadpb.Find
return nil
}

func (mets *Cmets) newFindingAid(cfg *DaoConfig) (eadpb.FindingAid, error) {
fa := eadpb.FindingAid{
func (mets *Cmets) newFindingAid(cfg *DaoConfig) (*eadpb.FindingAid, error) {
fa := &eadpb.FindingAid{
ArchiveID: cfg.ArchiveID,
InventoryID: cfg.InventoryID,
InventoryPath: cfg.InventoryPath,
Expand All @@ -178,7 +178,7 @@ func (mets *Cmets) newFindingAid(cfg *DaoConfig) (eadpb.FindingAid, error) {
return fa, err
}

err = updateFileInfo(files, mets.CfileSec.CfileGrp, &fa)
err = updateFileInfo(files, mets.CfileSec.CfileGrp, fa)
if err != nil {
return fa, err
}
Expand Down
8 changes: 4 additions & 4 deletions hub3/ead/mets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func TestFindingAidMimeTypes(t *testing.T) {
t.Errorf("not all mimetypes counted, got %d: want %d", count, 140)
}

if len(getMimeTypes(&findingAid)) != 1 {
t.Errorf("wrong count for mime-types, got %d: want %d", len(getMimeTypes(&findingAid)), 1)
if len(getMimeTypes(findingAid)) != 1 {
t.Errorf("wrong count for mime-types, got %d: want %d", len(getMimeTypes(findingAid)), 1)
}

if getMimeTypes(&findingAid)[0] != "image/jpeg" {
t.Errorf("not the right mime-type array, got %#v", getMimeTypes(&findingAid))
if getMimeTypes(findingAid)[0] != "image/jpeg" {
t.Errorf("not the right mime-type array, got %#v", getMimeTypes(findingAid))
}
}

Expand Down
1 change: 1 addition & 0 deletions hub3/ead/number_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build ignore
// +build ignore

package main
Expand Down
8 changes: 4 additions & 4 deletions hub3/fragments/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,13 +1346,13 @@ func (sr *SearchRequest) executeBatchAggregations(ec *elastic.Client, fub *Facet
batchFieldNames := make([]string, 0, len(facetBatch))
for _, facetField := range facetBatch {
// Create a size-limited copy of the facet field
facetCopy := *facetField
facetCopy := proto.Clone(facetField).(*FacetField)
if sr.FacetLimit != 0 {
facetCopy.Size = sr.FacetLimit
}

// Create aggregation for this specific field
agg, err := sr.CreateAggregationBySearchLabel(resourcesEntries, &facetCopy, fub)
agg, err := sr.CreateAggregationBySearchLabel(resourcesEntries, facetCopy, fub)
if err != nil {
return nil, fmt.Errorf("failed to create aggregation for %s: %w", facetField.GetField(), err)
}
Expand Down Expand Up @@ -1478,9 +1478,9 @@ func (sr *SearchRequest) CreateAggregationBySearchLabel(path string, facet *Face
// TERMS falls through to the default case, which builds the
// composite value listing we need for sortValue ordering.
if facet.GetType() == FacetType_FIELDS && facet.GetByName() {
facetCopy := *facet
facetCopy := proto.Clone(facet).(*FacetField)
facetCopy.Type = FacetType_TERMS
facet = &facetCopy
facet = facetCopy
}

return CreateAggregationBySearchLabel(path, facet, sr.FacetAndBoolType, fub)
Expand Down
2 changes: 1 addition & 1 deletion hub3/fragments/example_semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ func TestSemanticFormatExample(t *testing.T) {
require.Equal(t, "fr", frDesc.Language)

fmt.Println("\nExample semantic format test completed successfully!")
}
}
11 changes: 5 additions & 6 deletions hub3/fragments/fragments.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ func (fr *FragmentRequest) Find(ctx context.Context, client *elastic.Client) ([]

seen := map[string]bool{}

var frtyp Fragment
for idx, item := range res.Each(reflect.TypeOf(frtyp)) {
frag := item.(Fragment)
for idx, item := range res.Each(reflect.TypeOf(&Fragment{})) {
frag := item.(*Fragment)

// if subject is the prefix of the named graph then return the whole graph
if idx == 0 && len(fr.Subject) != 0 {
Expand All @@ -243,7 +242,7 @@ func (fr *FragmentRequest) Find(ctx context.Context, client *elastic.Client) ([]

_, ok := seen[frag.Triple]
if !ok {
fragments = append(fragments, &frag)
fragments = append(fragments, frag)
seen[frag.Triple] = true
}
}
Expand Down Expand Up @@ -271,7 +270,7 @@ func (f *Fragment) ID() string {

// CreateBulkIndexRequest converts the fragment into a request that can be
// submitted to the ElasticSearch BulkIndexService
func (f Fragment) IndexMessage() (*domainpb.IndexMessage, error) {
func (f *Fragment) IndexMessage() (*domainpb.IndexMessage, error) {
b, err := json.Marshal(f)
if err != nil {
return nil, err
Expand All @@ -288,7 +287,7 @@ func (f Fragment) IndexMessage() (*domainpb.IndexMessage, error) {
}

// AddTo adds the BulkableRequest to the Storage interface where it is flushed periodically.
func (f Fragment) AddTo(bi BulkIndex) error {
func (f *Fragment) AddTo(bi BulkIndex) error {
m, err := f.IndexMessage()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion hub3/fragments/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type FragmentGraph struct {
}

type RelatedItems struct {
Items []*ItemV1 `json:"item,omitempty"`
Items []*ItemV1 `json:"item,omitempty"`
SemanticItems []*FragmentGraph `json:"items,omitempty"`
}

Expand Down
20 changes: 10 additions & 10 deletions hub3/fragments/searchfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type FieldInfo struct {
func detectSearchFields(query string) FieldInfo {
// Custom parsing implementation for field detection
// This is more robust than using a single regex pattern

// Handle special cases first
if query == "" {
return FieldInfo{
Expand All @@ -25,27 +25,27 @@ func detectSearchFields(query string) FieldInfo {
Count: 0,
}
}

// Check for valid field pattern: field:value
// A valid field name must:
// 1. Start with a letter or underscore
// 2. Contain only letters, numbers, dots, or underscores
// 3. Be followed by a colon and not at the end of a string
// 4. Not be preceded by another alphanumeric, dot or underscore

// Basic check for valid field patterns
validFieldRegex := regexp.MustCompile(`(^|[^a-zA-Z0-9_])([a-zA-Z_][a-zA-Z0-9_.]*):\S`)

matches := validFieldRegex.FindAllStringSubmatch(query, -1)

if len(matches) == 0 {
return FieldInfo{
HasFields: false,
Fields: []string{},
Count: 0,
}
}

// Extract unique field names
fieldSet := make(map[string]bool)
for _, match := range matches {
Expand All @@ -54,12 +54,12 @@ func detectSearchFields(query string) FieldInfo {
fieldSet[fieldName] = true
}
}

// Handle specific edge cases that should not match
// Check for "text with colon: but no field"
invalidColonRegex := regexp.MustCompile(`\s\w+:(\s|$)`)
invalidMatches := invalidColonRegex.FindAllString(query, -1)

// If we only have invalid matches (like "text: " or "colon: "), return no fields
if len(invalidMatches) > 0 && len(fieldSet) == 1 {
for field := range fieldSet {
Expand All @@ -76,13 +76,13 @@ func detectSearchFields(query string) FieldInfo {
}
}
}

// Convert to slice
fields := make([]string, 0, len(fieldSet))
for field := range fieldSet {
fields = append(fields, field)
}

return FieldInfo{
HasFields: true,
Fields: fields,
Expand Down
Loading
Loading