Skip to content

Commit 876aeee

Browse files
committed
2 parents 7054e99 + c9c02a1 commit 876aeee

File tree

17 files changed

+316
-313
lines changed

17 files changed

+316
-313
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# Azurite files for local environment
107+
__azurite_*

search-website-functions-v4/api/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"azureFunctions.pythonVenv": ".venv",
55
"azureFunctions.projectLanguage": "Python",
66
"azureFunctions.projectRuntime": "~4",
7-
"debug.internalConsoleOptions": "neverOpen"
7+
"debug.internalConsoleOptions": "neverOpen",
8+
"azureFunctions.projectLanguageModel": 2
89
}

search-website-functions-v4/api/Lookup/function.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

search-website-functions-v4/api/Search/function.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

search-website-functions-v4/api/Suggest/function.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

search-website-functions-v4/api/Suggest/sample.dat

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import azure.functions as func
2+
import logging
3+
import json
4+
from search import bp as search_bp
5+
from lookup import bp as lookup_bp
6+
from suggest import bp as suggest_bp
7+
8+
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
9+
10+
app.register_functions(lookup_bp)
11+
app.register_functions(search_bp)
12+
app.register_functions(suggest_bp)
13+
14+

search-website-functions-v4/api/host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"extensionBundle": {
1212
"id": "Microsoft.Azure.Functions.ExtensionBundle",
13-
"version": "[3.*, 4.0.0)"
13+
"version": "[4.*, 5.0.0)"
1414
}
1515
}

search-website-functions-v4/api/local.settings.json.rename

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"IsEncrypted": false,
33
"Values": {
44
"AzureWebJobsStorage": "",
5+
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
56
"FUNCTIONS_WORKER_RUNTIME": "python",
67
"SearchApiKey": "YOUR-SEARCH-QUERY-KEY",
78
"SearchServiceName": "YOUR-SEARCH-RESOURCE-NAME",
Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
import logging
2-
import azure.functions as func
3-
from azure.core.credentials import AzureKeyCredential
4-
from azure.search.documents import SearchClient
5-
from shared_code import azure_config
6-
import json
7-
8-
environment_vars = azure_config()
9-
10-
# Set Azure Search endpoint and key
11-
endpoint = f'https://{environment_vars["search_service_name"]}.search.windows.net'
12-
key = environment_vars["search_api_key"]
13-
14-
# Your index name
15-
index_name = "good-books"
16-
17-
# Create Azure SDK client
18-
search_client = SearchClient(endpoint, index_name, AzureKeyCredential(key))
19-
20-
21-
def main(req: func.HttpRequest) -> func.HttpResponse:
22-
23-
# http://localhost:7071/api/Lookup?id=100
24-
docid = req.params.get("id")
25-
26-
if docid:
27-
logging.info(f"/Lookup id = {docid}")
28-
returnedDocument = search_client.get_document(key=docid)
29-
30-
full_response = {}
31-
full_response["document"] = returnedDocument
32-
33-
return func.HttpResponse(
34-
body=json.dumps(full_response), mimetype="application/json", status_code=200
35-
)
36-
else:
37-
return func.HttpResponse("No doc id param found.", status_code=200)
1+
import logging
2+
import azure.functions as func
3+
from azure.core.credentials import AzureKeyCredential
4+
from azure.search.documents import SearchClient
5+
from shared_code import azure_config
6+
import json
7+
8+
environment_vars = azure_config()
9+
10+
# Set Azure Search endpoint and key
11+
endpoint = f'https://{environment_vars["search_service_name"]}.search.windows.net'
12+
key = environment_vars["search_api_key"]
13+
14+
# Your index name
15+
index_name = "good-books"
16+
17+
# Create Azure SDK client
18+
search_client = SearchClient(endpoint, index_name, AzureKeyCredential(key))
19+
20+
bp = func.Blueprint()
21+
@bp.function_name("lookup")
22+
@bp.route(route="lookup", methods=[func.HttpMethod.GET, func.HttpMethod.POST])
23+
def main(req: func.HttpRequest) -> func.HttpResponse:
24+
25+
# http://localhost:7071/api/Lookup?id=100
26+
docid = req.params.get("id")
27+
28+
if docid:
29+
logging.info(f"/Lookup id = {docid}")
30+
returnedDocument = search_client.get_document(key=docid)
31+
32+
full_response = {}
33+
full_response["document"] = returnedDocument
34+
35+
return func.HttpResponse(
36+
body=json.dumps(full_response), mimetype="application/json", status_code=200
37+
)
38+
else:
39+
return func.HttpResponse("No doc id param found.", status_code=200)

0 commit comments

Comments
 (0)