Compare commits
8 Commits
0.1.0
...
4a673d1894
Author | SHA1 | Date | |
---|---|---|---|
4a673d1894 | |||
0d22da3643 | |||
0107f77570 | |||
d5f658244b | |||
72128f97a3 | |||
78e2568e2b | |||
75ba450d9b | |||
dd7f0c0a28 |
@@ -10,7 +10,7 @@ on:
|
||||
jobs:
|
||||
renovate:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/renovatebot/renovate:39.215.2
|
||||
container: ghcr.io/renovatebot/renovate:39.216.1
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: renovate
|
||||
|
23
.gitea/workflows/sonarqube.yaml
Normal file
23
.gitea/workflows/sonarqube.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
name: SonarQube Scan
|
||||
jobs:
|
||||
sonarqube:
|
||||
name: SonarQube Trigger
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checking out
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# Disabling shallow clone is recommended for improving relevancy of reporting
|
||||
fetch-depth: 0
|
||||
- name: SonarQube Scan
|
||||
uses: kitabisa/sonarqube-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.SONARQUBE_HOST }}
|
||||
login: ${{ secrets.SONARQUBE_TOKEN }}
|
11
CHANGELOG.md
11
CHANGELOG.md
@@ -6,6 +6,16 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- *(index)* Add save and load functionality for Index using gob encoding/decoding
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
- Add first release in Changelog
|
||||
|
||||
## [0.1.0] - 2025-03-25
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- Added documentation for gosearch system architecture and updated Go module version to 1.23.5
|
||||
- Update internal HTTP server to use Fiber v2 with new routes and middleware configuration
|
||||
- Added new search route and metric endpoint to internal controller
|
||||
@@ -30,5 +40,6 @@ All notable changes to this project will be documented in this file.
|
||||
- Added golang workflow for building and testing project
|
||||
- Update Go version in build-and-test workflow to 1.23
|
||||
- Added renovate configuration files for Gitea workflow automation
|
||||
- Add release pipeline
|
||||
|
||||
<!-- generated by git-cliff -->
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func SearchQuery(c *fiber.Ctx) error {
|
||||
query := c.Params("query")
|
||||
query = strings.TrimSpace(strings.ToLower(query))
|
||||
query = strings.TrimSpace(query)
|
||||
|
||||
terms, queryType := parseQuery(query)
|
||||
results := search.Search(terms, queryType, index.Index, index.DocFreq, len(index.Documents))
|
||||
@@ -29,12 +29,12 @@ func SearchQuery(c *fiber.Ctx) error {
|
||||
|
||||
// parseQuery parses the query to determine query type and terms
|
||||
func parseQuery(query string) ([]string, string) {
|
||||
if strings.Contains(query, "AND") {
|
||||
return strings.Split(query, " AND "), "AND"
|
||||
} else if strings.Contains(query, "OR") {
|
||||
return strings.Split(query, " OR "), "OR"
|
||||
if strings.Contains(strings.ToLower(query), "AND") {
|
||||
return strings.Split(strings.ToLower(query), " AND "), "AND"
|
||||
} else if strings.Contains(strings.ToLower(query), "OR") {
|
||||
return strings.Split(strings.ToLower(query), " OR "), "OR"
|
||||
}
|
||||
return strings.Fields(query), "SIMPLE"
|
||||
return strings.Fields(strings.ToLower(query)), "SIMPLE"
|
||||
}
|
||||
|
||||
// phraseMatch checks if all terms appear in the given document in sequence
|
||||
|
2
main.go
2
main.go
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func main() {
|
||||
// Initialize Index
|
||||
index.CreateIndex()
|
||||
index.InitIndex("default")
|
||||
|
||||
// Start HTTP Server
|
||||
http.StartService()
|
||||
|
@@ -2,6 +2,12 @@ package index
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -13,7 +19,40 @@ var Index InvertedIndex
|
||||
var DocFreq DocumentFrequency
|
||||
var Documents []string
|
||||
|
||||
func CreateIndex() {
|
||||
type SavedIndex struct {
|
||||
Index InvertedIndex
|
||||
DocFreq DocumentFrequency
|
||||
Documents []string
|
||||
}
|
||||
|
||||
func InitIndex(name string) {
|
||||
createIndex()
|
||||
|
||||
// check if index as file exists
|
||||
// if not, create one and save it
|
||||
indexFilePath := "/tmp/" + name + ".db"
|
||||
if _, err := os.Stat(indexFilePath); errors.Is(err, os.ErrNotExist) {
|
||||
f, err := os.Create(indexFilePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
} else {
|
||||
var savedIndex SavedIndex
|
||||
|
||||
err = readStructFromFile(indexFilePath, &savedIndex)
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Lesen:", err)
|
||||
return
|
||||
}
|
||||
|
||||
Index = savedIndex.Index
|
||||
DocFreq = savedIndex.DocFreq
|
||||
Documents = savedIndex.Documents
|
||||
}
|
||||
}
|
||||
|
||||
func createIndex() {
|
||||
index := make(InvertedIndex)
|
||||
docFreq := make(DocumentFrequency)
|
||||
var docs []string
|
||||
@@ -23,6 +62,21 @@ func CreateIndex() {
|
||||
DocFreq = docFreq
|
||||
}
|
||||
|
||||
func updateIndex(name string) {
|
||||
savedIndex := SavedIndex{
|
||||
Index: Index,
|
||||
DocFreq: DocFreq,
|
||||
Documents: Documents,
|
||||
}
|
||||
|
||||
indexFilePath := "/tmp/" + name + ".db"
|
||||
err := writeStructToFile(indexFilePath, savedIndex)
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Schreiben:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func AddDocToIndex(url string, content string) {
|
||||
Documents = append(Documents, url)
|
||||
|
||||
@@ -46,4 +100,35 @@ func AddDocToIndex(url string, content string) {
|
||||
}
|
||||
}
|
||||
|
||||
updateIndex("default")
|
||||
}
|
||||
|
||||
func writeStructToFile(filename string, data interface{}) error {
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
err := enc.Encode(data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error when encoding the structs: %w", err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(filename, buf.Bytes(), 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error when writing to the file: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func readStructFromFile(filename string, data interface{}) error {
|
||||
content, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading the file: %w", err)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(content)
|
||||
dec := gob.NewDecoder(buf)
|
||||
err = dec.Decode(data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error when decoding the structs: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user