Skip to content

Commit

Permalink
added "Look up" API
Browse files Browse the repository at this point in the history
  • Loading branch information
s33chin committed Jun 9, 2024
1 parent 8119095 commit 3e23a50
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
19 changes: 19 additions & 0 deletions api/Lookup/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
34 changes: 34 additions & 0 deletions api/Lookup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { SearchClient, AzureKeyCredential } = require("@azure/search-documents");

const indexName = process.env["SearchIndexName"];
const apiKey = process.env["SearchApiKey"];
const searchServiceName = process.env["SearchServiceName"];

// Create a SearchClient to send queries
const client = new SearchClient(
`https://` + searchServiceName + `.search.windows.net/`,
indexName,
new AzureKeyCredential(apiKey)
);

module.exports = async function (context, req) {

//context.log(req);

// Reading inputs from HTTP Request
const id = (req.query.id || (req.body && req.body.id));

// Returning the document with the matching id
const document = await client.getDocument(id)

context.log(document);

context.res = {
// status: 200, /* Defaults to 200 */
headers: {
"Content-type": "application/json"
},
body: { document: document}
};

};
Binary file added frontend/public/images/research-paper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions frontend/src/components/Results/Result/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import React from 'react';
import './Result.css';

export default function Result(props) {
return(
<div className="card result">
const maxLength = 50;
const content = props.document.content.length > maxLength ? props.document.content.substring(0, maxLength) + '...' : props.document.content;

return (
<div className="card result">
<img className="card-img-top" src={'/images/research-paper.png'} alt="Place Holder"></img>
<div className="card-body">
<h6 className="title-style">{props.document.content}</h6>
<h6 className="title-style">{content}</h6>
</div>
</div>
</div>
);
}

0 comments on commit 3e23a50

Please sign in to comment.