/**
  * For facets that are associated with elements, `getOriginalLabel` should
  * return the name of the parent element.
  */
 public function testElementFacets()
 {
     $title = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Title');
     $facet = new SolrSearchField($title);
     // Should return the parent element.
     $this->assertEquals('Title', $facet->getOriginalLabel());
 }
 /**
  * `findByElementName` should return the facet linked to a given element.
  */
 public function testFindByElement()
 {
     $title = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Title');
     $field = new SolrSearchField($title);
     $field->save();
     $retrieved = $this->fieldTable->findByElementName('Dublin Core', 'Title');
     $this->assertEquals($field->id, $retrieved->id);
 }
 /**
  * `facetKey` should return the `_s`-suffixed slug when the field is
  * associated with a metadata element.
  */
 public function testElementField()
 {
     // Get the Dublin Core "Title" field.
     $title = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Title');
     $field = new SolrSearchField($title);
     // Should add the `_s` suffix.
     $this->assertEquals("{$title->id}_s", $field->facetKey());
 }
 /**
  * `findBySlug` should return the facet with a given slug.
  */
 public function testFindBySlug()
 {
     $field = new SolrSearchField();
     $field->label = 'field';
     $field->slug = 'field';
     $field->save();
     $retrieved = $this->fieldTable->findBySlug('field');
     $this->assertEquals($field->id, $retrieved->id);
 }
 /**
  * `groupByElementSet` should return the facets grouped by element set.
  */
 public function testGroupByElementSet()
 {
     // Get the "Dublin Core" element set.
     $dublinCore = $this->elementSetTable->findByName('Dublin Core');
     // Get the "Item Type Metadata" element set.
     $itemTypeMetadata = $this->elementSetTable->findByName('Item Type Metadata');
     // Get the Dublin Core "Date" field.
     $date = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Date');
     // Get the Dublin Core "Coverage" field.
     $coverage = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Coverage');
     // Get the Item Type Metadata "To" field.
     $to = $this->elementTable->findByElementSetNameAndElementName('Item Type Metadata', 'To');
     // Get the Item Type Metadata "From" field.
     $from = $this->elementTable->findByElementSetNameAndElementName('Item Type Metadata', 'From');
     // Facet with no element:
     $noElementSetFacet1 = new SolrSearchField();
     $noElementSetFacet1->slug = 'no_element_set_1';
     $noElementSetFacet1->label = 'No Element Set 1';
     $noElementSetFacet1->save();
     // Facet with no element:
     $noElementSetFacet2 = new SolrSearchField();
     $noElementSetFacet2->slug = 'no_element_set_2';
     $noElementSetFacet2->label = 'No Element Set 2';
     $noElementSetFacet2->save();
     // Facet for Dublin Core element:
     $dublinCoreFacet1 = new SolrSearchField($date);
     $dublinCoreFacet1->slug = 'dublin_core_1';
     $dublinCoreFacet1->label = 'Dublin Core 1';
     $dublinCoreFacet1->save();
     // Facet for Dublin Core element:
     $dublinCoreFacet2 = new SolrSearchField($coverage);
     $dublinCoreFacet2->slug = 'dublin_core_2';
     $dublinCoreFacet2->label = 'Dublin Core 2';
     $dublinCoreFacet2->save();
     // Facet for Item Type Metadata element:
     $itemTypeMetadataFacet1 = new SolrSearchField($to);
     $itemTypeMetadataFacet1->slug = 'item_type_metadata_1';
     $itemTypeMetadataFacet1->label = 'Item Type Metadata 1';
     $itemTypeMetadataFacet1->save();
     // Facet for Item Type Metadata element:
     $itemTypeMetadataFacet2 = new SolrSearchField($from);
     $itemTypeMetadataFacet2->slug = 'item_type_metadata_2';
     $itemTypeMetadataFacet2->label = 'Item Type Metadata 2';
     $itemTypeMetadataFacet2->save();
     // Get the facet groups.
     $groups = $this->fieldTable->groupByElementSet();
     // Should group Omeka category facets:
     $this->assertEquals($noElementSetFacet1->id, $groups['Omeka Categories'][0]['id']);
     $this->assertEquals($noElementSetFacet2->id, $groups['Omeka Categories'][1]['id']);
     // Should group Dublin Core facets:
     $this->assertEquals($dublinCoreFacet1->id, $groups['Dublin Core'][0]['id']);
     $this->assertEquals($dublinCoreFacet2->id, $groups['Dublin Core'][1]['id']);
     // Should group Item Type Metadata facets:
     $this->assertEquals($itemTypeMetadataFacet1->id, $groups['Item Type Metadata'][0]['id']);
     $this->assertEquals($itemTypeMetadataFacet2->id, $groups['Item Type Metadata'][1]['id']);
 }
 /**
  * `findByText` should return the facet linked to a given text.
  */
 public function testFindByText()
 {
     $title = $this->elementTable->findByElementSetNameAndElementName('Dublin Core', 'Title');
     // Create a field for "Title".
     $field = new SolrSearchField($title);
     $field->save();
     // Get a "Title" element text.
     $texts = $this->_item()->getElementTexts('Dublin Core', 'Title');
     $retrieved = $this->fieldTable->findByText($texts[0]);
     $this->assertEquals($field->id, $retrieved->id);
 }
 /**
  * When a new element is added, register a facet mapping for it.
  *
  * @param array $args With `record` and `insert`.
  */
 public function hookAfterSaveElement($args)
 {
     if ($args['insert']) {
         $facet = new SolrSearchField($args['record']);
         $facet->save();
     }
 }
 /**
  * `getElement` should return NULL when no element is defined.
  */
 public function testNoParentElement()
 {
     $facet = new SolrSearchField();
     // Should return NULL.
     $this->assertNull($facet->getElementSet());
 }
 /**
  * Updates the facets with elements that have been added since
  * `installFacets` was called.
  */
 public function updateFacetMappings()
 {
     $facetSet = array();
     foreach ($this->findAll() as $facet) {
         $facetSet[$facet->element_id] = $facet;
     }
     $elementTable = $this->_db->getTable('Element');
     $elementSet = array();
     foreach ($elementTable->findAll() as $element) {
         if (!array_key_exists($element->id, $facetSet)) {
             $facet = new SolrSearchField($element);
             $facet->save();
         } else {
             $elementSet[$element->id] = TRUE;
         }
     }
     foreach ($facetSet as $facetId => $facet) {
         if (!array_key_exists($facetId, $elementSet)) {
             $facet->delete();
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Install the default facet mappings.
  *
  * @param string $slug The facet `slug`.
  * @param string $label The facet `label`.
  */
 protected function _installGenericFacet($slug, $label)
 {
     $facet = new SolrSearchField();
     $facet->slug = $slug;
     $facet->label = $label;
     $facet->is_indexed = 1;
     $facet->is_facet = 1;
     $facet->save();
 }
 /**
  * Create a field.
  *
  * @param string $slug The facet slug.
  * @param string $label The facet label.
  * @return SolrSearchField
  */
 protected function _field($slug, $label = 'Test Label')
 {
     $field = new SolrSearchField();
     $field->slug = $slug;
     $field->label = $label;
     $field->save();
     return $field;
 }
 /**
  * `getElement` should return NULL when no element is defined.
  */
 public function testNoParentElement()
 {
     $facet = new SolrSearchField();
     // False when no parent element exists.
     $this->assertFalse($facet->hasElement());
 }