Skip to content

Commit

Permalink
#FOIMOD-3636 PUSH TO SOLR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abin-aot committed Dec 25, 2024
1 parent 02d8eda commit 3bd0528
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"azuredocextractservice/azureservices"
"azuredocextractservice/httpservices"
"azuredocextractservice/s3services"
"azuredocextractservice/solrsearchservices"
"azuredocextractservice/types"
"fmt"
"log"
"net/url"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -36,9 +38,30 @@ func main() {
var parsedURL = document.DocumentS3URL
var jsonStrbytes []byte = getBytesfromDocumentPath(parsedURL)
analysisResults, _analyzeerr := azureservices.CallAzureDocument(jsonStrbytes)
if _analyzeerr != nil {
if _analyzeerr == nil && analysisResults.Status == "succeeded" {

searchdocumentpagelines := []types.SOLRSearchDocument{}
//pUSH to solr.
//analysisResults.AnalyzeResult.Pages
for _, page := range analysisResults.AnalyzeResult.Pages {
for _, line := range page.Lines {
_solrsearchdocuemnt := types.SOLRSearchDocument{
FoiDocumentID: strconv.Itoa(int(document.DocumentID)),
FoiRequestNumber: request.RequestNumber,
FoiMinistryRequestID: request.MinistryRequestID,
FoiMinistryCode: request.MinistryCode,
FoiDocumentFileName: document.DocumentName,
FoiDocumentPageNumber: page.PageNumber,
FoiDocumentSentence: line.Content,
FoiRequestMiscInfo: document.DocumentS3URL,
}
searchdocumentpagelines = append(searchdocumentpagelines, _solrsearchdocuemnt)
fmt.Println(_solrsearchdocuemnt.FoiDocumentFileName)
}

}

solrsearchservices.PushtoSolr(searchdocumentpagelines)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package solrsearchservices

import (
"azuredocextractservice/types"
"azuredocextractservice/utils"
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
)

func PushtoSolr(searchdocs []types.SOLRSearchDocument) bool {

// Convert the struct to JSON
jsonData, err := json.Marshal(searchdocs)
fmt.Println("SOLR Search Data starts here")
fmt.Println(string(jsonData))
fmt.Println("SOLR Search Data ends here")
if err != nil {
log.Fatal("Error marshaling JSON:", err)
}

// Solr endpoint URL (Replace with your Solr endpoint)
url := utils.ViperEnvVariable("foisearchsolrpostendpoint")
// Create a POST request with JSON data
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
log.Fatal("Error creating request:", err)
}

// Set the appropriate headers for JSON content
req.Header.Set("Content-Type", "application/json")
username := utils.ViperEnvVariable("solradmin")
password := utils.ViperEnvVariable("solrpassword")
req.SetBasicAuth(username, password)
// Send the request using the http client
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("Error sending request:", err)
}
defer resp.Body.Close()

// Handle the response
if resp.StatusCode == http.StatusOK {
fmt.Println("Successfully posted to Solr")
return true
} else {
fmt.Printf("Failed to post to Solr. Status: %s\n", resp.Status)
return false
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package types

type SOLRSearchDocument struct {
FoiDocumentID string `json:"foidocumentid"`
FoiRequestNumber string `json:"foirequestnumber"`
FoiMinistryRequestID string `json:"foiministryrequestid"`
FoiMinistryCode string `json:"foiministrycode"`
FoiDocumentFileName string `json:"foidocumentfilename"`
FoiDocumentPageNumber int `json:"foidocumentpagenumber"`
FoiDocumentSentence string `json:"foidocumentsentence"`
FoiDocumentSentenceID int `json:"foidocumentsentenceId"`
FoiRequestMiscInfo string `json:"foirequestmiscinfo"`
}

0 comments on commit 3bd0528

Please sign in to comment.