Skip to content

Commit

Permalink
Merge branch 'dev' into vufind-1233
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 15, 2023
2 parents 1be30df + d05ba3a commit 7622e42
Show file tree
Hide file tree
Showing 27 changed files with 370 additions and 99 deletions.
Binary file modified import/browse-indexing.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions index-alphabetic-browse.bat
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mkdir "%index_dir%"

rem These parameters should match the ones in solr/vufind/biblio/conf/solrconfig.xml - BrowseRequestHandler
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse hierarchy hierarchy_browse
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse title title_fullStr 1 "-Dbibleech=StoredFieldLeech -Dsortfield=title_sort -Dvaluefield=title_fullStr -Dbrowse.normalizer=org.vufind.util.TitleNormalizer"
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse title title_fullStr 1 "-Dbib_field_iterator=org.vufind.solr.indexing.StoredFieldIterator -Dsortfield=title_sort -Dvaluefield=title_fullStr -Dbrowse.normalizer=org.vufind.util.TitleNormalizer"
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse topic topic_browse
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse author author_browse
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse lcc callnumber-raw 1 "-Dbrowse.normalizer=org.vufind.util.LCCallNormalizer"
Expand Down Expand Up @@ -113,7 +113,7 @@ set args="%bib_index%" "%field%" "%auth_index%" "%browse%.tmp"
:skipauth

rem Get the browse headings from Solr
%JAVA% %jvmopts% -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp %CLASSPATH% PrintBrowseHeadings %args%
%JAVA% %jvmopts% -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp %CLASSPATH% org.vufind.solr.indexing.PrintBrowseHeadings %args%

rem Sort the browse headings
sort %browse%.tmp /o sorted-%browse%.tmp /rec 65535
Expand All @@ -122,7 +122,7 @@ rem Remove duplicate lines
php %VUFIND_HOME%\util\dedupe.php "sorted-%browse%.tmp" "unique-%browse%.tmp"

rem Build the SQLite database
%JAVA% -Dfile.encoding="UTF-8" -cp %CLASSPATH% CreateBrowseSQLite "unique-%browse%.tmp" "%browse%_browse.db"
%JAVA% -Dfile.encoding="UTF-8" -cp %CLASSPATH% org.vufind.solr.indexing.CreateBrowseSQLite "unique-%browse%.tmp" "%browse%_browse.db"

rem Clear up temp files
del /q *.tmp > nul
Expand Down
8 changes: 4 additions & 4 deletions index-alphabetic-browse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ function build_browse

# Get the browse headings from Solr
if [ "$skip_authority" = "1" ]; then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH PrintBrowseHeadings "$bib_index" "$field" "${browse}.tmp" 2>&1); then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "${browse}.tmp" 2>&1); then
echo "ERROR: Failed to create browse headings for ${browse}. ${output}."
exit 1
fi
else
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH PrintBrowseHeadings "$bib_index" "$field" "$auth_index" "${browse}.tmp" 2>&1); then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "$auth_index" "${browse}.tmp" 2>&1); then
echo "ERROR: Failed to create browse headings for ${browse}. ${output}."
exit 1
fi
Expand All @@ -105,7 +105,7 @@ function build_browse
fi

# Build the SQLite database
if ! output=$($JAVA -Dfile.encoding="UTF-8" -cp $CLASSPATH CreateBrowseSQLite "sorted-${browse}.tmp" "${browse}_browse.db" 2>&1); then
if ! output=$($JAVA -Dfile.encoding="UTF-8" -cp $CLASSPATH org.vufind.solr.indexing.CreateBrowseSQLite "sorted-${browse}.tmp" "${browse}_browse.db" 2>&1); then
echo "ERROR: Failed to build the SQLite database for ${browse}. ${output}."
exit 1
fi
Expand All @@ -130,7 +130,7 @@ function build_browse
}
# These parameters should match the ones in solr/vufind/biblio/conf/solrconfig.xml - BrowseRequestHandler
build_browse "hierarchy" "hierarchy_browse"
build_browse "title" "title_fullStr" 1 "-Dbibleech=StoredFieldLeech -Dsortfield=title_sort -Dvaluefield=title_fullStr -Dbrowse.normalizer=org.vufind.util.TitleNormalizer"
build_browse "title" "title_fullStr" 1 "-Dbib_field_iterator=org.vufind.solr.indexing.StoredFieldIterator -Dsortfield=title_sort -Dvaluefield=title_fullStr -Dbrowse.normalizer=org.vufind.util.TitleNormalizer"
build_browse "topic" "topic_browse"
build_browse "author" "author_browse"
build_browse "lcc" "callnumber-raw" 1 "-Dbrowse.normalizer=org.vufind.util.LCCallNormalizer"
Expand Down
4 changes: 3 additions & 1 deletion module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ protected function formatFacets(
= $this->getCheckboxFacetCount($facet, $results);
} else {
$context['facet'] = $facet;
$context['cluster'] = $facetSet[$facet] ?? [];
$context['cluster'] = $facetSet[$facet] ?? [
'list' => [],
];
$context['collapsedFacets'] = [];
$response[$facet]['html'] = $this->renderer->render(
'Recommend/SideFacets/facet.phtml',
Expand Down
12 changes: 12 additions & 0 deletions module/VuFind/src/VuFind/Search/Base/HideFacetValueListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use VuFindSearch\Backend\BackendInterface;
use VuFindSearch\Service;

use function is_callable;

/**
* Hide single facet values from displaying.
*
Expand Down Expand Up @@ -139,10 +141,14 @@ protected function processHideFacetValue($event)
}
$facets = $result->getFacets();

// Count how many values have been filtered as we go:
$filteredFacetCounts = [];

foreach ($this->hideFacets as $facet => $values) {
foreach ((array)$values as $value) {
if (isset($facets[$facet][$value])) {
unset($facets[$facet][$value]);
$filteredFacetCounts[$facet] = ($filteredFacetCounts[$facet] ?? 0) + 1;
}
}
}
Expand All @@ -155,11 +161,17 @@ protected function processHideFacetValue($event)
foreach ($valuesToHide as $valueToHide) {
if (isset($facets[$facet][$valueToHide])) {
unset($facets[$facet][$valueToHide]);
$filteredFacetCounts[$facet] = ($filteredFacetCounts[$facet] ?? 0) + 1;
}
}
}
}

// If the result object is capable of receiving filter counts, send the data:
if (is_callable([$result, 'setFilteredFacetCounts'])) {
$result->setFilteredFacetCounts($filteredFacetCounts);
}

$result->setFacets($facets);
}
}
23 changes: 22 additions & 1 deletion module/VuFind/src/VuFind/Search/Solr/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class Results extends \VuFind\Search\Base\Results
*/
protected $responsePivotFacets = null;

/**
* Counts of filtered-out facet values, indexed by field name.
*/
protected $filteredFacetCounts = null;

/**
* Search backend identifier.
*
Expand Down Expand Up @@ -202,6 +207,7 @@ protected function performSearch()
$this->extraSearchBackendDetails = $command->getExtraRequestDetails();

$this->responseFacets = $collection->getFacets();
$this->filteredFacetCounts = $collection->getFilteredFacetCounts();
$this->responseQueryFacets = $collection->getQueryFacets();
$this->responsePivotFacets = $collection->getPivotFacets();
$this->resultTotal = $collection->getTotal();
Expand Down Expand Up @@ -314,6 +320,20 @@ public function getFacetList($filter = null)
return $this->buildFacetList($this->responseFacets, $filter);
}

/**
* Get counts of facet values filtered out by the HideFacetValueListener,
* indexed by field name.
*
* @return array
*/
public function getFilteredFacetCounts(): array
{
if (null === $this->filteredFacetCounts) {
$this->performAndProcessSearch();
}
return $this->filteredFacetCounts;
}

/**
* Get complete facet counts for several index fields
*
Expand Down Expand Up @@ -377,14 +397,15 @@ public function getPartialFieldFacets(

// Do search
$result = $clone->getFacetList();
$filteredCounts = $clone->getFilteredFacetCounts();

// Reformat into a hash:
foreach ($result as $key => $value) {
// Detect next page and crop results if necessary
$more = false;
if (
isset($page) && count($value['list']) > 0
&& count($value['list']) == $limit + 1
&& (count($value['list']) + ($filteredCounts[$key] ?? 0)) == $limit + 1
) {
$more = true;
array_pop($value['list']);
Expand Down
Loading

0 comments on commit 7622e42

Please sign in to comment.