Skip to content

Commit

Permalink
added n_visible to the rooms-facet
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Apr 9, 2024
1 parent 464b096 commit aab2339
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
18 changes: 17 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,19 @@ paths:
name: 5503.EG.350 (Egbert-von-Hoyer-Hörsaal)
subtext: Maschinenwesen (MW)
subtext_bold: 0350@5503
n_visible: 5
estimatedTotalHits: 3655
time_ms: 16
nothing:
value:
sections:
- facet: sites_buildings
entries: []
n_visible: 0
estimatedTotalHits: 0
- facet: rooms
entries: []
n_visible: 0
estimatedTotalHits: 0
time_ms: 6
interims-2:
Expand Down Expand Up @@ -252,6 +255,7 @@ paths:
name: 5416.EG.010 (IT/Audio)
subtext: 'Interimshörsäle II, Jürgen Manchot-Hörsaalgebäude'
subtext_bold: 010@5416
n_visible: 4
estimatedTotalHits: 23
time_ms: 23
'400':
Expand Down Expand Up @@ -1661,7 +1665,18 @@ components:
type: array
items:
$ref: '#/components/schemas/RoomEntry'
n_visible:
description: |
A recommendation how many of the entries should be displayed by default.
The number is usually from 0-20.
More results might be displayed when clicking "expand".
If this field is not present, then all entries are displayed.
type: integer
format: int64
example: 20
minimum: 0
required:
- n_visible
- estimatedTotalHits
- facet
- entries
Expand Down Expand Up @@ -1694,6 +1709,7 @@ components:
example: 6
minimum: 0
required:
- n_visible
- estimatedTotalHits
- facet
- entries
Expand Down Expand Up @@ -1850,7 +1866,7 @@ components:
If this field is not present, then all entries are displayed.
type: integer
format: int64
example: 6
example: 5
minimum: 0
required:
- entries
Expand Down
18 changes: 10 additions & 8 deletions server/main-api/src/search/search_executor/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub(super) fn merge_search_results(
let mut section_buildings = super::SearchResultsSection {
facet: "sites_buildings".to_string(),
entries: Vec::new(),
n_visible: None,
n_visible: 0,
estimated_total_hits: res_buildings.estimated_total_hits.unwrap_or(0),
};
let mut section_rooms = super::SearchResultsSection {
facet: "rooms".to_string(),
entries: Vec::new(),
n_visible: None,
n_visible: 0,
estimated_total_hits: res_rooms.estimated_total_hits.unwrap_or(0),
};

Expand All @@ -40,9 +40,11 @@ pub(super) fn merge_search_results(
observed_ids.push(hit.result.id.clone());

// Total limit reached (does only count visible results)
let current_buildings_cnt = section_buildings
.n_visible
.unwrap_or(section_buildings.entries.len());
let current_buildings_cnt = if section_buildings.n_visible == 0 {
section_buildings.entries.len()
} else {
section_buildings.n_visible
};
if section_rooms.entries.len() + current_buildings_cnt >= args.limit_all {
break;
}
Expand Down Expand Up @@ -76,16 +78,16 @@ pub(super) fn merge_search_results(
});

// The first room in the results 'freezes' the number of visible buildings
if section_buildings.n_visible.is_none() && section_rooms.entries.len() == 1
{
section_buildings.n_visible = Some(section_buildings.entries.len());
if section_buildings.n_visible == 0 && section_rooms.entries.len() == 1 {
section_buildings.n_visible = section_buildings.entries.len();
}
}
}
_ => {}
};
}
}
section_rooms.n_visible = section_rooms.entries.len();

(section_buildings, section_rooms)
}
Expand Down
5 changes: 2 additions & 3 deletions server/main-api/src/search/search_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use serde::Serialize;
pub struct SearchResultsSection {
facet: String,
entries: Vec<ResultEntry>,
#[serde(skip_serializing_if = "Option::is_none")]
n_visible: Option<usize>,
n_visible: usize,
#[serde(rename = "estimatedTotalHits")]
estimated_total_hits: usize,
}
Expand Down Expand Up @@ -63,7 +62,7 @@ pub async fn do_geoentry_search(
.for_each(|r| visitor.visit(r));

match section_buildings.n_visible {
Some(0) => vec![section_rooms, section_buildings],
0 => vec![section_rooms, section_buildings],
_ => vec![section_buildings, section_rooms],
}
}
Expand Down
4 changes: 1 addition & 3 deletions webclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ pnpm run format
From the folder of this README, run:

```sh
npx openapi-typescript ../openapi.yaml --output ./api_types/index.ts --export-type --immutable-types --support-array-length
pnpm run lint
pnpm run format
pnpm run type-refresh
```

## Architecture
Expand Down
14 changes: 12 additions & 2 deletions webclient/api_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ export type components = {
*/
readonly estimatedTotalHits: number;
readonly entries: readonly components["schemas"]["RoomEntry"][];
/**
* Format: int64
* @description A recommendation how many of the entries should be displayed by default.
* The number is usually from 0-20.
* More results might be displayed when clicking "expand".
* If this field is not present, then all entries are displayed.
*
* @example 20
*/
readonly n_visible: number;
};
readonly SitesBuildings: {
/**
Expand All @@ -430,7 +440,7 @@ export type components = {
*
* @example 6
*/
readonly n_visible?: number;
readonly n_visible: number;
};
readonly RoomEntry: components["schemas"]["SitesBuildingsEntry"] & {
/** @description Subtext to show below the search (by default in bold and after the non-bold subtext). Usually contains the arch-id of the room, which is another common room id format, and supports highlighting. */
Expand Down Expand Up @@ -508,7 +518,7 @@ export type components = {
* More results might be displayed when clicking "expand".
* If this field is not present, then all entries are displayed.
*
* @example 6
* @example 5
*/
readonly n_visible: number;
};
Expand Down
2 changes: 2 additions & 0 deletions webclient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"type-check": "nuxt typecheck",
"type-refresh": "openapi-typescript ../openapi.yaml --output ./api_types/index.ts --export-type --immutable-types --support-array-length && npm run format && npm run lint",
"lint": "eslint . --ext .vue,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --plugin=prettier-plugin-tailwindcss --write ."
},
Expand Down Expand Up @@ -41,6 +42,7 @@
"autoprefixer": "10.4.19",
"eslint": "8.57.0",
"eslint-plugin-vue": "9.24.0",
"openapi-typescript": "^6.7.5",
"postcss": "8.4.38",
"prettier": "3.2.5",
"prettier-plugin-tailwindcss": "0.5.13",
Expand Down
8 changes: 3 additions & 5 deletions webclient/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aab2339

Please sign in to comment.