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

searhcHits as field in manifestations :) #480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/datasources/complexsearch.datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ function prefixFacets(facets) {
* Search via complex search
*/
export async function load(
{ cql, offset, limit, profile, filters, sort, facets, facetLimit },
{
cql,
offset,
limit,
profile,
filters,
sort,
facets,
facetLimit,
includeFilteredPids,
},
context
) {
const body = {
Expand All @@ -35,6 +45,7 @@ export async function load(
facets: prefixFacets(facets || []),
facetLimit: facetLimit,
trackingId: context?.trackingId,
includeFilteredPids: includeFilteredPids || false,
...(sort && { sort: sort }),
};

Expand Down Expand Up @@ -67,6 +78,7 @@ export async function load(
tokenizerDurationInMs: json?.tokenizerDurationInMs || 0,
solrExecutionDurationInMs: json?.solrExecutionDurationInMs || 0,
solrFilter: json?.solrFilter || "",
searchHits: json.expanded || null,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/middlewares/dataHubMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export function dataHubMiddleware(req, res, next) {
offset: input?.offset || 0,
limit: input?.limit || 10,
sort: input?.sort,
includeFilteredPids: input?.includeFilteredPids || false,
};

const identifiers = result?.works?.map((w) => ({
Expand Down
11 changes: 8 additions & 3 deletions src/schema/complexsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function setPost(parent, context, args) {
filters: parent.filters,
facets: parent?.facets?.facets,
facetLimit: parent?.facets?.facetLimit,
includeFilteredPids: parent?.includeFilteredPids || false,
...(args && args),
};
}
Expand Down Expand Up @@ -265,16 +266,20 @@ export const resolvers = {
const res = await context.datasources
.getLoader("complexsearch")
.load(setPost(parent, context, args));
const expanded = await Promise.all(
res?.works?.map(async (id) => resolveWork({ id }, context))

const resolvedWorks = await Promise.all(
res?.works?.map(async (id) =>
resolveWork({ id, searchHits: res?.searchHits }, context)
)
);

const input = {
...parent,
...args,
profile: context.profile,
};
const works = expanded.filter((work) => !!work);

const works = resolvedWorks.filter((work) => !!work);
context?.dataHub?.createComplexSearchEvent({
input: input,
result: { works },
Expand Down
13 changes: 13 additions & 0 deletions src/schema/draft/manifestation.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,16 @@ type LevelForAudience {
Level expressed as integer on a scale from 1 to 5
"""
realisticVsFictional: Int
}

type HighLightType {
hit: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HighLightType skal nok justeres, hvis vi når dertil

Vi vil gerne kunne vise hele feltet der er hittet og så markere den del af strengen der er hittet.

Men fint til en start

field: [String!]
}

type SearchHitsType {
match: Manifestation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synes match er et godt navn, bravo

highlights: [HighLightType]
}

type Manifestations {
Expand All @@ -574,6 +583,10 @@ type Manifestations {
all: [Manifestation!]! @complexity(value: 50)
bestRepresentation: Manifestation!
mostRelevant: [Manifestation!]! @complexity(value: 25)
"""
Complex search only !!! - manifestations with search hits
"""
searchHits: [SearchHitsType]
}

type Manifestation {
Expand Down
2 changes: 2 additions & 0 deletions src/schema/draft/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,15 @@ export const resolvers = {
const bestRepresentation =
manifestations?.bestRepresentations?.[0] || manifestations?.all?.[0];
const mostRelevant = manifestations?.mostRelevant || manifestations?.all;
const searchHits = manifestations?.searchHits || null;

return {
first,
latest,
all,
bestRepresentation,
mostRelevant,
searchHits,
};
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/schema/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Query {
work(id: String, faust: String, pid: String, oclc: String, language: LanguageCodeEnum): Work @complexity(value: 5)
works(id: [String!], faust: [String!], pid: [String!], oclc:[String!], language: LanguageCodeEnum): [Work]! @complexity(value: 5, multipliers: ["id", "pid", "faust", "oclc"])
search(q: SearchQueryInput!, filters: SearchFiltersInput, search_exact: Boolean): SearchResponse!
complexSearch(cql: String!, filters: ComplexSearchFiltersInput, facets: ComplexSearchFacetsInput): ComplexSearchResponse!
complexSearch(cql: String!, filters: ComplexSearchFiltersInput, includeFilteredPids: Boolean, facets: ComplexSearchFacetsInput): ComplexSearchResponse!
linkCheck: LinkCheckService! @complexity(value: 10, multipliers: ["urls"])
"""
ComplexFacets is for internal use only - there is no limit on how many facets are allowed to extract
Expand Down
12 changes: 12 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ export async function resolveWork(args, context) {
...m,
traceId: createTraceId(),
})),
searchHits: () => {
return args?.searchHits
? w?.manifestations?.all
?.filter((m) => args?.searchHits?.[w.workId]?.includes(m.pid))
.map((m) => ({
match: { ...m, traceId: createTraceId() },
// highlights is an empty array for now
// @TODO find the highlights in matches array from search query (cql)
highlights: [],
}))
: null;
},
};

return withTraceId;
Expand Down