Skip to content
Snippets Groups Projects
Commit 52465ba4 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

Merge branch 'hotline#161009_recherches_infructueuses' into 'master'

hotline#161009 : itemcallnumber is indexed with simple search

See merge request !4572
parents f50f3936 632e12cd
Branches
Tags
1 merge request!4572hotline#161009 : itemcallnumber is indexed with simple search
Pipeline #18968 passed with stage
in 23 minutes and 20 seconds
- correctif #161009 : Recherche : Les données des exemplaires, tels que la côte, sont de nouveaux utilisables pour la recherche.
\ No newline at end of file
......@@ -194,6 +194,15 @@ class Class_Exemplaire extends Storm_Model_Abstract {
}
public function getItemZone() : string {
return (($data_profile = $this->getDataProfile())
&& ($item_zone = $data_profile->getItemZone()))
? $item_zone
: Class_IntProfilDonnees::FIELD_ITEM_ZONE_DEFAULT;
}
public function getBestCote() : string {
$cote = $this->getCote();
......
......@@ -74,20 +74,20 @@ class Class_Exemplaire_Fields {
: '';
$writer->setNotice($unimarc);
$writer->add_field('995', ' 1', $this->_asKeyValue());
$writer->add_field('995', ' 1', $this->asKeyValue());
return $writer->toUnimarcIso2709();
}
public function toString() {
$ret = '';
foreach($this->_asKeyValue() as $key_value)
foreach($this->asKeyValue() as $key_value)
$ret .= $key_value[0] . '=' . $key_value[1] . '<br>';
return $ret;
}
protected function _asKeyValue() {
public function asKeyValue() : array {
$subfields = [];
foreach ($this->_fields as $key => $values)
array_map(function($value) use (&$subfields, $key)
......
......@@ -377,6 +377,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract {
FIELD_TYPE_DOC_RECOGNITION = 'type_doc',
FIELD_ITEM_ZONE = 'item_zone',
FIELD_ITEM_ZONE_DEFAULT = '995',
FIELD_ITEM_TYPE_DOC = 'champ_type_doc',
FIELD_ITEM_BARCODE = 'champ_code_barres',
FIELD_ITEM_COTE = 'champ_cote',
......
......@@ -25,6 +25,7 @@ class Class_Notice_Indexation {
protected Class_Notice $_record;
protected Class_Indexation $_indexation;
protected string $_item_zone_cache;
public function __construct(Class_Notice $record) {
$this->_record = $record;
......@@ -54,7 +55,10 @@ class Class_Notice_Indexation {
protected function _getOtherTerms() : string {
return trim($this
if ($this->_itemsDataUsage())
$this->_addItems();
$html = trim($this
->_indexation->getFulltextOtherTerms($this->_record->getOtherIndexedTerms(),
[$this->_record->getTitres(),
$this->_record->getAuteurs(),
......@@ -63,6 +67,66 @@ class Class_Notice_Indexation {
$this->_record->getMatieres()])
. ' '
. $this->_getIndexedThesauriTerms());
if ($this->_itemsDataUsage())
$this->_cleanItems();
return $html;
}
protected function getItemZone() :string {
if (isset($this->_item_zone_cache))
return $this->_item_zone_cache;
return $this->_item_zone_cache = $this->_getRecordItemZone();
}
protected function _getRecordFirstItem() : ?Class_Exemplaire {
if (get_class($this->_record) == Class_Notice::class)
return $this->_record->getFirstExemplaire();
return null;
}
protected function _getRecordItemZone() : string {
if ($item = $this->_record->getFirstExemplaire())
return $item->getItemZone();
return '';
}
protected function _getRecordItems() : array {
return $this->_record->getExemplaires();
}
protected function _addItemToRecord($item) : Class_NoticeUnimarc {
return $this->_record->addItem($item, $this->getItemZone());
}
protected function _addItems() : self {
array_map(fn($item) => $this->_addItemToRecord($item), $this->_getRecordItems());
return $this;
}
protected function _itemsDataUsage() : bool {
if (!$other_index_fields = trim(Class_Cosmovar::get('other_index_fields')))
return false;
if (!($item_zone = $this->getItemZone()))
return false;
return (false !== strpos($other_index_fields, $item_zone));
}
protected function _cleanItems() : self {
$this->_record->deleteZone($this->getItemZone());
return $this;
}
......
......@@ -337,6 +337,37 @@ class Class_NoticeUnimarc {
}
public function addZone(Class_NoticeUnimarc_Zone $zone) :self {
$field_number = $zone->getLabel();
if (!isset($this->inner_data[$field_number])){
$this->inner_data[$field_number] = [$zone->render()];
return $this;
}
$this->inner_data[$field_number] []= $zone->render();
return $this;
}
public function deleteZone(string $label) :self {
if (!isset($this->inner_data[$label])){
unset($this->inner_data[$label]);
}
return $this;
}
public function addItem(Class_Exemplaire $item, string $item_zone) :self{
$subfields = (new Class_Exemplaire_Fields($item))->asKeyValue();
$zone = (new Class_NoticeUnimarc_Zone())->label($item_zone);
foreach ($subfields as $subfield)
$zone->addChildFrom($subfield);
$this->addZone($zone);
return $this;
}
public function get_zone(string $label, string $content) : Class_NoticeUnimarc_Zone {
$content = str_replace($this->rgx_field_end, '', $content);
$instance = (new Class_NoticeUnimarc_Zone)->label($label);
......
......@@ -43,6 +43,11 @@ class Class_NoticeUnimarc_Zone {
}
public function getLabel() : string {
return (string) $this->_label;
}
public function content(string $content) : self {
$this->_content = $content;
$this->_sub_zones = new Storm_Collection;
......@@ -58,6 +63,12 @@ class Class_NoticeUnimarc_Zone {
}
public function addChildFrom(array $subfield) : self {
if (isset($subfield[0]) && isset($subfield[1]))
return $this->addChild($subfield[0], $subfield[1]);
}
public function addChild(string $code, string $value) : self {
$this->_sub_zones
->append(new Class_NoticeUnimarc_SubZone($code, $value));
......
......@@ -137,3 +137,69 @@ class IndexationWithLotOfTitlesTest extends ModelTestCase {
$this->assertEquals('DROIT FONDAMENTAL DROI FONDAMANTAL', Class_Notice::find(3)->getCollection());
}
}
class IndexationWithOtherIndexTermsWithItemsElementsTest extends ModelTestCase {
public function setUp() {
parent::setUp();
Class_CosmoVar::setValueOf('other_index_fields', '200$a;200$f;995$k');
$this->fixture(Class_Notice::class,
['id' => 3,
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/unimarc_droit_administratif.txt')]);
$this->fixture(Class_Exemplaire::class,
['id' => 3,
'id_notice' => 3
])->setZone995(serialize([
['code' => 'a',
'valeur' => 'UMEA'],
['code' => 'c',
'valeur' => 'qdsf'],
['code' => 'f',
'valeur' => '0123456789'],
['code' => 'n',
'valeur' => 'orderlineid'],
['code' => 'v',
'valeur' => 'activite'],
['code' => 'k',
'valeur' => '1E11 302.801']]));
$this->fixture(Class_Exemplaire::class,
['id' => 4,
'id_notice' => 3
])->setZone995(serialize([
['code' => 'a',
'valeur' => 'UMEA'],
['code' => 'c',
'valeur' => 'qdsf'],
['code' => 'f',
'valeur' => '0123456799'],
['code' => 'n',
'valeur' => 'orderlineid'],
['code' => 'v',
'valeur' => 'activite'],
['code' => 'k',
'valeur' => '305.801']]));
array_map(fn($n) => (new Class_Notice_Indexation($n))->indexAndSave(),
Class_Notice::findAll());
}
/** @test */
public function otherTermsForRecordThreeShouldContainsFirstItemCallnumber() {
$this->assertContains('1E11',
Class_Notice::find(3)->getOtherTerms());
}
/** @test */
public function otherTermsForRecordThreeShouldContainsSecondItemCallnumber() {
$this->assertContains('305 801',
Class_Notice::find(3)->getOtherTerms());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment