-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from bcgov/dev-AA-FOIMOD-3636
#foimod-3636 SOLR push updates
- Loading branch information
Showing
10 changed files
with
332 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
computingservices/documentextractservices/azuredocextractservice/src/foiazuredocextractservice | ||
.vscode/* | ||
.vscode/* | ||
computingservices/documentextractservices/azuredocextractservice/src/.env |
15 changes: 15 additions & 0 deletions
15
computingservices/documentextractservices/azuredocextractservice/src/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
.../documentextractservices/azuredocextractservice/src/azureservices/azuredocumentservice.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
package azureservices | ||
|
||
import ( | ||
"azuredocextractservice/types" | ||
"azuredocextractservice/utils" | ||
"log" | ||
) | ||
|
||
func CallAzureDocument(jsonPayload []byte) { | ||
subscriptionKey := "abcd" | ||
func CallAzureDocument(jsonPayload []byte) (types.AnalyzeResults, error) { | ||
subscriptionKey := utils.ViperEnvVariable("azuresubcriptionkey") | ||
baseURL := "https://foidocintelservice.cognitiveservices.azure.com" | ||
|
||
service := NewAzureService(subscriptionKey, baseURL) | ||
|
||
// Example JSON payload | ||
//jsonPayload := []byte(`{"url": "https://example.com/sample.pdf"}`) | ||
|
||
err := service.AnalyzeAndExtractDocument(jsonPayload) | ||
result, err := service.AnalyzeAndExtractDocument(jsonPayload) | ||
if err != nil { | ||
log.Fatalf("Error calling Azure Document API: %v", err) | ||
} | ||
|
||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ocumentextractservices/azuredocextractservice/src/solrsearchservices/solrsearchservice.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
Oops, something went wrong.