Browse Source

Merge pull request #545 from albig/search-plugin-enhance

Fix search in documents for hierarchical documents like newspaper.
pull/605/head
Sebastian Meyer 2 years ago committed by GitHub
parent
commit
f20a9e6d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Classes/Common/Solr.php
  2. 25
      Classes/Plugin/Search.php
  3. 2
      Configuration/ApacheSolr/configsets/dlf/conf/schema.xml
  4. 4
      Resources/Private/Language/Search.xml

6
Classes/Common/Solr.php

@ -366,12 +366,6 @@ class Solr
$params['filterquery'] = isset($params['filterquery']) ? $params['filterquery'] : [];
// Restrict the fields to the required ones.
$params['fields'] = 'uid,id';
// Extend filter query to get all documents with the same uids.
foreach ($params['filterquery'] as $key => $value) {
if (isset($value['query'])) {
$params['filterquery'][$key]['query'] = '{!join from=uid to=uid}' . $value['query'];
}
}
// Set filter query to just get toplevel documents.
$params['filterquery'][] = ['query' => 'toplevel:true'];
// Set join query to get all documents with the same uids.

25
Classes/Plugin/Search.php

@ -105,7 +105,7 @@ class Search extends \Kitodo\Dlf\Common\AbstractPlugin
*
* @access protected
*
* @return string HTML input fields with current document's UID and parent ID
* @return string HTML input fields with current document's UID
*/
protected function addCurrentDocument()
{
@ -117,19 +117,25 @@ class Search extends \Kitodo\Dlf\Common\AbstractPlugin
&& \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['id'])
) {
$this->loadDocument();
// Get document's UID or parent ID.
// Get document's UID
if ($this->doc->ready) {
return '<input type="hidden" name="' . $this->prefixId . '[id]" value="' . ($this->doc->parentId > 0 ? $this->doc->parentId : $this->doc->uid) . '" />';
return '<input type="hidden" name="' . $this->prefixId . '[id]" value="' . ($this->doc->uid) . '" />';
}
} elseif (!empty($list->metadata['options']['params']['filterquery'])) {
// Get document's UID from search metadata.
// The string may be e.g. "{!join from=uid to=partof}uid:{!join from=uid to=partof}uid:2" OR {!join from=uid to=partof}uid:2 OR uid:2"
// or "collection_faceting:("Some Collection Title")"
foreach ($list->metadata['options']['params']['filterquery'] as $facet) {
$facetKeyVal = explode(':', $facet['query']);
if ($facetKeyVal[0] == 'uid') {
$documentId = (int) substr($facetKeyVal[1], 1, strpos($facetKeyVal[1], ')'));
if (($lastUidPos = strrpos($facet['query'], 'uid:')) !== false) {
$facetKeyVal = explode(':', substr($facet['query'], $lastUidPos));
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($facetKeyVal[1])) {
$documentId = (int) $facetKeyVal[1];
}
}
}
return '<input type="hidden" name="' . $this->prefixId . '[id]" value="' . $documentId . '" />';
if (!empty($documentId)) {
return '<input type="hidden" name="' . $this->prefixId . '[id]" value="' . $documentId . '" />';
}
}
return '';
}
@ -453,7 +459,10 @@ class Search extends \Kitodo\Dlf\Common\AbstractPlugin
!empty($this->piVars['id'])
&& \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['id'])
) {
$params['filterquery'][]['query'] = 'uid:(' . $this->piVars['id'] . ') OR partof:(' . $this->piVars['id'] . ')';
// Search in document and all subordinates (valid for up to three levels of hierarchy).
$params['filterquery'][]['query'] = '_query_:"{!join from=uid to=partof}uid:{!join from=uid to=partof}uid:' . $this->piVars['id'] . '"' .
' OR {!join from=uid to=partof}uid:' . $this->piVars['id'] .
' OR uid:' . $this->piVars['id'];
$label .= htmlspecialchars(sprintf($this->pi_getLL('in', ''), Document::getTitle($this->piVars['id'])));
}
}

2
Configuration/ApacheSolr/configsets/dlf/conf/schema.xml

@ -107,7 +107,7 @@ limitations under the License.
<!-- Image number where this document starts. -->
<field name="page" type="int" indexed="false" stored="true" required="true" default="0" />
<!-- Unique identifier for the parent document in the TYPO3 database. Only if this is a multi-volume work! -->
<field name="partof" type="int" indexed="true" stored="true" required="true" default="0" />
<field name="partof" type="int" indexed="true" stored="true" required="true" default="0" docValues="true" />
<!-- Unique identifier for the root document in the TYPO3 database. Only if this is a multi-volume work! -->
<field name="root" type="int" indexed="true" stored="true" required="true" default="0" />
<!-- XML ID of this document in the METS file. This is only unique within the METS file! -->

4
Resources/Private/Language/Search.xml

@ -28,7 +28,7 @@
<label index="tt_content.pi_flexform.collections">Restrict search to these collections</label>
<label index="tt_content.pi_flexform.searchIn">Restrict search to current document or collection?</label>
<label index="tt_content.pi_flexform.searchIn.none">none</label>
<label index="tt_content.pi_flexform.searchIn.document">document only</label>
<label index="tt_content.pi_flexform.searchIn.document">document only (incl. subordinates)</label>
<label index="tt_content.pi_flexform.searchIn.collection">collection only</label>
<label index="tt_content.pi_flexform.searchIn.all">both</label>
<label index="tt_content.pi_flexform.facets">Show these facets</label>
@ -71,7 +71,7 @@
<label index="tt_content.pi_flexform.collections">Suche auf diese Kollektionen einschränken</label>
<label index="tt_content.pi_flexform.searchIn">Suche auf aktuelle/s Kollektion/Dokument einschränken?</label>
<label index="tt_content.pi_flexform.searchIn.none">nein</label>
<label index="tt_content.pi_flexform.searchIn.document">nur Dokument</label>
<label index="tt_content.pi_flexform.searchIn.document">nur Dokument (inkl. Unterordnungen)</label>
<label index="tt_content.pi_flexform.searchIn.collection">nur Kollektion</label>
<label index="tt_content.pi_flexform.searchIn.all">beides</label>
<label index="tt_content.pi_flexform.facets">Diese Facetten anzeigen</label>

Loading…
Cancel
Save