Skip to content

Commit

Permalink
Merge pull request #1065 from metabrainz/search-indexing-issues
Browse files Browse the repository at this point in the history
feat: Improve search indexing reliability
  • Loading branch information
MonkeyDo authored Feb 16, 2024
2 parents d913bdb + 311ea9b commit 2622d7c
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 203 deletions.
21 changes: 14 additions & 7 deletions src/client/components/pages/parts/search-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ import {genEntityIconHTMLElement} from '../../../helpers/entity';

const {Alert, Badge, Button, ButtonGroup, Table} = bootstrap;

// Main entities have a BBID but some other indexed types
// have an ID field instead (collections, editors, areas)
function getId(entity) {
return entity.bbid ?? entity.id;
}

/**
* Renders the document and displays the 'SearchResults' page.
* @returns {ReactElement} a HTML document which displays the SearchResults.
Expand Down Expand Up @@ -89,8 +95,8 @@ class SearchResults extends React.Component {
// eslint-disable-next-line react/no-access-state-in-setstate
const oldSelected = this.state.selected;
let newSelected;
if (oldSelected.find(selected => selected.bbid === entity.bbid)) {
newSelected = oldSelected.filter(selected => selected.bbid !== entity.bbid);
if (oldSelected.find(selected => getId(selected) === getId(entity))) {
newSelected = oldSelected.filter(selected => getId(selected) !== getId(entity));
}
else {
newSelected = [...oldSelected, entity];
Expand Down Expand Up @@ -148,6 +154,7 @@ class SearchResults extends React.Component {
if (!result) {
return null;
}
const id = getId(result);
const name = result.defaultAlias ? result.defaultAlias.name :
'(unnamed)';

Expand All @@ -160,19 +167,19 @@ class SearchResults extends React.Component {
const disambiguation = result.disambiguation ? <small>({result.disambiguation.comment})</small> : '';
// No redirect link for Area entity results
const link = result.type === 'Area' ?
`//musicbrainz.org/area/${result.bbid}` :
`/${_kebabCase(result.type)}/${result.bbid}`;
`//musicbrainz.org/area/${id}` :
`/${_kebabCase(result.type)}/${id}`;

/* eslint-disable react/jsx-no-bind */
return (
<tr key={result.bbid}>
<tr key={id}>
{
!this.props.condensed &&
<td>
{
this.props.user ?
<input
checked={this.state.selected.find(selected => selected.bbid === result.bbid)}
checked={this.state.selected.find(selected => getId(selected) === id)}
className="checkboxes"
type="checkbox"
onChange={() => this.toggleRow(result)}
Expand Down Expand Up @@ -212,7 +219,7 @@ class SearchResults extends React.Component {
this.props.user ?
<div>
<AddToCollectionModal
bbids={this.state.selected.map(selected => selected.bbid)}
bbids={this.state.selected.map(getId)}
closeModalAndShowMessage={this.closeModalAndShowMessage}
entityType={this.state.selected[0]?.type}
handleCloseModal={this.onCloseModal}
Expand Down
Loading

0 comments on commit 2622d7c

Please sign in to comment.