Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URLs to PDF search results. #8

Merged
merged 2 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions medicines/web/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// .env
AZURE_API_VERSION=2017-11-11
AZURE_INDEX=azureblob-index
AZURE_KEY=6D6107C925CC3C284A9218EFC626C7F7
AZURE_SERVICE=rb-mhra-mip
AZURE_WORD_FUZZINESS=1
//.env
AZURE_SEARCH_API_VERSION=2017-11-11
AZURE_SEARCH_INDEX=azureblob-index
AZURE_SEARCH_KEY=6D6107C925CC3C284A9218EFC626C7F7
AZURE_SEARCH_SERVICE=rb-mhra-mip
AZURE_SEARCH_WORD_FUZZINESS=1
18 changes: 9 additions & 9 deletions medicines/web/src/components/mip/azure-search.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const azureApiVersion = process.env.AZURE_API_VERSION;
const azureIndex = process.env.AZURE_INDEX;
const azureKey = process.env.AZURE_KEY;
const azureService = process.env.AZURE_SERVICE;
const azureWordFuzziness = process.env.AZURE_WORD_FUZZINESS;
const azureSearchApiVersion = process.env.AZURE_SEARCH_API_VERSION;
m-doughty marked this conversation as resolved.
Show resolved Hide resolved
const azureSearchIndex = process.env.AZURE_SEARCH_INDEX;
const azureSearchKey = process.env.AZURE_SEARCH_KEY;
const azureSearchService = process.env.AZURE_SEARCH_SERVICE;
const azureSearchWordFuzziness = process.env.AZURE_SEARCH_WORD_FUZZINESS;

enum DocType {
PilLabel,
Expand All @@ -23,7 +23,7 @@ const escapeSpecialCharacters = (word: string): string =>
word.replace(/([+\-!(){}\[\]^"~*?:\/]|\|\||&&)/gi, `\\$1`);

const addAzureWordFuzziness = (word: string): string =>
`${word}~${azureWordFuzziness}`;
`${word}~${azureSearchWordFuzziness}`;

const buildFuzzyQuery = (query: string): string => {
return query
Expand All @@ -35,11 +35,11 @@ const buildFuzzyQuery = (query: string): string => {

const buildAzureSearchUrl = (query: string): string => {
const url = new URL(
`https://${azureService}.search.windows.net/indexes/${azureIndex}/docs`,
`https://${azureSearchService}.search.windows.net/indexes/${azureSearchIndex}/docs`,
);

url.searchParams.append('api-key', azureKey as string);
url.searchParams.append('api-version', azureApiVersion as string);
url.searchParams.append('api-key', azureSearchKey as string);
url.searchParams.append('api-version', azureSearchApiVersion as string);
url.searchParams.append('highlight', 'content');
url.searchParams.append('queryType', 'full');
url.searchParams.append('search', query);
Expand Down
2 changes: 1 addition & 1 deletion medicines/web/src/components/mip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Mip: React.FC = () => {
setResults(
(await azureSearch(search)).map((drug: IAzureSearchResult) => ({
name: drug['@search.highlights'].content.join(' … '),
url: '',
url: atob(drug.metadata_storage_path),
})),
);
};
Expand Down