Skip to content

Commit

Permalink
Merge pull request #6 from xsga/v5.0.2
Browse files Browse the repository at this point in the history
Fix advanced search error
  • Loading branch information
xsga authored May 27, 2024
2 parents bc90725 + db17a93 commit 7b74258
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,23 @@ public function getAdvSearchResultsDto(): SearchResultsDto
// Add search result as root child.
$dom->appendChild($dom->importNode($result->item($i), true));

// Gets film release date.
$data = strtolower(preg_replace('~\s+~u', '', $dom->textContent));
$dataAux = preg_replace("#\(\d{4}\)#", '#', $data);
$position = strpos($dataAux, '#');
$year = substr($data, $position, 6);

// New DOMXPath instance.
$domXpath = new DOMXPath($dom);

// Get data.
$titleResult = $domXpath->query(XpathCons::SEARCH_TITLE);
$idResult = $domXpath->query(XpathCons::SEARCH_ID);
$yearResult = $domXpath->query(XpathCons::SEARCH_YEAR_ADV);

// Prepare data.
$title = $titleResult->item(0)->nodeValue;
$id = $idResult->item(0)->getAttribute('data-movie-id');
$year = $yearResult->item(1)->nodeValue;

// Set result data.
$searchResult = new SingleSearchResultDto();
$searchResult->id = (int)trim($id);
$searchResult->title = trim(str_replace(' ', ' ', trim(str_replace(' ', ' ', $title))) . ' ' . $year);
$searchResult->title = trim(str_replace(' ', ' ', trim(str_replace(' ', ' ', $title))) . ' (' . $year . ')');

// Put single result data into output DTO.
$out->results[] = $searchResult;
Expand Down
11 changes: 10 additions & 1 deletion src/Xsga/FilmAffinityApi/Business/Parser/XpathCons.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,23 @@ final class XpathCons
public const SEARCH_RESULTS = "//div[contains(@class, 'se-it')]";

/**
* XPath query to get film year om simple search results.
* XPath query to get film year on simple search results.
*
* @var string
*
* @access public
*/
public const SEARCH_YEAR = "//div[contains(@class, 'ye-w')]";

/**
* XPath query to get film year on advanced search results.
*
* @var string
*
* @access public
*/
public const SEARCH_YEAR_ADV = "//span[contains(@class, 'mc-year')]";

/**
* XPath query to get film ID in search results.
*
Expand Down

0 comments on commit 7b74258

Please sign in to comment.