Skip to content

Commit

Permalink
Authors controller (#112)
Browse files Browse the repository at this point in the history
* Added authors controller

* WIP

* Fixed link to related docs

* Use ellipsis in cover large texts, cleaned up API

* Added missing tranlations

* Updated tests

* Cleanup

* Further cleanup

* Added test
  • Loading branch information
svera authored Dec 9, 2024
1 parent f677f4a commit 987191f
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 166 deletions.
13 changes: 13 additions & 0 deletions internal/index/author.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package index

type Author struct {
Slug string
Name string
Type string
}

// BleveType is part of the bleve.Classifier interface and its purpose is to tell the indexer
// the type of the document, which will be used to decide which analyzer will parse it.
func (a Author) BleveType() string {
return "author"
}
23 changes: 14 additions & 9 deletions internal/index/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import (

// Version identifies the mapping used for indexing. Any changes in the mapping requires an increase
// of version, to signal that a new index needs to be created.
const Version = "v3"
const Version = "v4"

const (
TypeDocument = "document"
TypeAuthor = "author"
)

// Metadata fields
var (
Expand Down Expand Up @@ -111,29 +116,29 @@ func CreateMapping() mapping.IndexMapping {

indexMapping.AddDocumentMapping(lang, bleve.NewDocumentMapping())
indexMapping.TypeMapping[lang].DefaultAnalyzer = lang
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Slug", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Title", noStopWordsTextFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Authors", simpleTextFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("AuthorsSlugs", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Description", textFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Subjects", textFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("SubjectsSlugs", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Series", noStopWordsTextFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Slug", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("SeriesEq", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("AuthorsEq", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("SubjectsEq", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("SeriesSlug", keywordFieldMapping)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Language", keywordFieldMappingNotIndexable)
indexMapping.TypeMapping[lang].AddFieldMappingsAt("Year", keywordFieldMappingNotIndexable)
}

indexMapping.DefaultMapping.DefaultAnalyzer = defaultAnalyzer
indexMapping.DefaultMapping.AddFieldMappingsAt("Slug", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Title", simpleTextFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Authors", simpleTextFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("AuthorsSlugs", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Description", simpleTextFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Subjects", simpleTextFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("SubjectsSlugs", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Series", simpleTextFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Slug", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("SeriesEq", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("AuthorsEq", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("SubjectsEq", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("SeriesSlug", keywordFieldMapping)
indexMapping.DefaultMapping.AddFieldMappingsAt("Language", keywordFieldMappingNotIndexable)
indexMapping.DefaultMapping.AddFieldMappingsAt("Year", keywordFieldMappingNotIndexable)

Expand Down
Loading

0 comments on commit 987191f

Please sign in to comment.