Skip to content

Commit

Permalink
fix: OpenLaw citation search
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Jul 6, 2024
1 parent 7ca4bd9 commit 3d06d14
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clerkent",
"version": "3.7.2",
"version": "3.7.3",
"private": true,
"description": "quick search legal search",
"repository": "https://github.com/lacuna-technologies/clerkent.git",
Expand Down
56 changes: 28 additions & 28 deletions src/utils/scraper/SG/OpenLaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Helpers from 'utils/Helpers'
import { CacheRequestConfig } from 'axios-cache-interceptor'

const SEARCH_API_URL = `https://api.lawnet.sg/lawnet/search-service/api/lawnetcore/search/supreme-court`
const CITATION_API_URL = `https://api.lawnet.sg/lawnet/search-service/api/lawnetcore/document/citation`
const PDF_DOWNLOAD_URL = `https://api.lawnet.sg/lawnet/search-service/api/lawnetcore/download/v1`
const defaultUserDevice = {
isBot: false,
Expand Down Expand Up @@ -56,40 +55,41 @@ const defaultRequestOptions = {
const getCaseByCitation = async (citation: string): Promise<Law.Case[]> => {
try {
const requestBody = {
...defaultCitationConfig,
...defaultSearchConfig,
data: {
...defaultCitationConfig.data,
citation,
...defaultSearchConfig.data,
searchQuery: `"${citation}"`,
},
}
const { data } = await Request.post(
CITATION_API_URL,
SEARCH_API_URL,
requestBody,
defaultRequestOptions as unknown as CacheRequestConfig,
)
const encodedCitation = citation.replaceAll(` `, `+`)
const judgmentLink: Law.Link = {
doctype: `Judgment`,
filetype: `HTML`,
url: `https://www.lawnet.com/openlaw/cases/citation/${encodedCitation}`,
}
const summaryLink: Law.Link = {
doctype: `Summary`,
filetype: `HTML`,
url: `https://www.lawnet.com/openlaw/cases/citation/${encodedCitation}`,
}
const result: Law.Case = {
citation: data.data.metadata[`NeutralCitation`][`NCit`],
database: Constants.DATABASES.SG_openlaw,
jurisdiction: Constants.JURISDICTIONS.SG.id,
links: [
summaryLink,
judgmentLink,
],
name: data.data.metadata[`CaseTitle`],
}
return [result]

const results: Law.Case[] = data.data.results.map((result): Law.Case => {
const encodedCitation = result.ncitation.replaceAll(` `, `+`)
const summaryLink: Law.Link = {
doctype: `Summary`,
filetype: `HTML`,
url: `https://www.lawnet.com/openlaw/cases/citation/${encodedCitation}`,
}
const judgmentLink: Law.Link = {
doctype: `Judgment`,
filetype: `HTML`,
url: `https://www.lawnet.com/openlaw/cases/citation/${encodedCitation}`,
}
return {
citation: result.ncitation,
database: Constants.DATABASES.SG_openlaw,
jurisdiction: Constants.JURISDICTIONS.SG.id,
links: [
summaryLink,
judgmentLink,
],
name: result.titles[0],
}
})
return results
} catch (error) {
Logger.error(error)
return []
Expand Down
39 changes: 10 additions & 29 deletions src/utils/scraper/SG/__tests__/__snapshots__/OpenLaw.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SG OpenLaw should parse getCaseByCitation result correctly 1`] = `
[
{
"citation": "[1999] SGHC 283",
"database": {
"icon": "",
"id": "SG_openlaw",
"name": "OpenLaw",
"url": "https://www.lawnet.com/openlaw",
},
"jurisdiction": "SG",
"links": [
{
"doctype": "Summary",
"filetype": "HTML",
"url": "https://www.lawnet.com/openlaw/cases/citation/[1999]+SGHC+283",
},
{
"doctype": "Judgment",
"filetype": "HTML",
"url": "https://www.lawnet.com/openlaw/cases/citation/[1999]+SGHC+283",
},
],
"name": "NV Sumatra Tobacco Co v Nanyang Brothers Tobacco Co Ltd",
},
]
`;
exports[`SG OpenLaw should parse getCaseByCitation result correctly 1`] = `[]`;

exports[`SG OpenLaw should send valid request for getCaseByCitation 1`] = `
[
[
"https://api.lawnet.sg/lawnet/search-service/api/lawnetcore/document/citation",
"https://api.lawnet.sg/lawnet/search-service/api/lawnetcore/search/supreme-court",
{
"data": {
"citation": "[1999] SGHC 283",
"filters": null,
"includeDraft": "true",
"orderBy": "relevancy-desc",
"pageLength": 10,
"searchDatabase": "allOfLawnet",
"searchQuery": ""[1999] SGHC 283"",
"searchSource": null,
"start": 1,
},
"info": {
"appId": "APP_LAWNET_ONE",
Expand Down

0 comments on commit 3d06d14

Please sign in to comment.