本文整理汇总了PHP中VuFindSearch\ParamBag::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ParamBag::set方法的具体用法?PHP ParamBag::set怎么用?PHP ParamBag::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VuFindSearch\ParamBag
的用法示例。
在下文中一共展示了ParamBag::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createBackendFilterParameters
/**
* Set up filters based on VuFind settings.
*
* @param ParamBag $params Parameter collection to update
*
* @return void
*/
public function createBackendFilterParameters(ParamBag $params)
{
// flag our non-Standard checkbox filters:
$foundIncludeNewspapers = false;
# includeNewspapers
$foundIncludeWithoutFulltext = false;
# includeWithoutFulltext
$filterList = $this->getFilterList();
// Which filters should be applied to our query?
if (!empty($filterList)) {
// Loop through all filters and add appropriate values to request:
foreach ($filterList as $filterArray) {
foreach ($filterArray as $filt) {
$safeValue = SummonQuery::escapeParam($filt['value']);
if ($filt['field'] == 'holdingsOnly') {
// Special case -- "holdings only" is a separate parameter from
// other facets.
$params->set('holdings', strtolower(trim($safeValue)) == 'true');
} else {
if ($filt['field'] == 'excludeNewspapers') {
// support a checkbox for excluding newspapers:
// this is now the default behaviour.
} else {
if ($filt['field'] == 'includeNewspapers') {
// explicitly include newspaper articles
$foundIncludeNewspapers = true;
} else {
if ($range = SolrUtils::parseRange($filt['value'])) {
// Special case -- range query (translate [x TO y] syntax):
$from = SummonQuery::escapeParam($range['from']);
$to = SummonQuery::escapeParam($range['to']);
$params->add('rangeFilters', "PublicationDate,{$from}:{$to}");
} else {
if ($filt['field'] == 'includeWithoutFulltext') {
$foundIncludeWithoutFulltext = true;
} else {
// Standard case:
$params->add('filters', "{$filt['field']},{$safeValue}");
}
}
}
}
}
}
}
}
// special cases (apply also when filter list is empty)
// newspaper articles
if (!$foundIncludeNewspapers) {
// this actually means: do *not* show newspaper articles
$params->add('filters', "ContentType,Newspaper Article,true");
}
// combined facet "with holdings/with fulltext"
if (!$foundIncludeWithoutFulltext) {
$params->set('holdings', true);
$params->add('filters', 'IsFullText,true');
} else {
$params->set('holdings', false);
}
}
示例2: testRemove
/**
* Test "remove"
*
* @return void
*/
public function testRemove()
{
$bag = new ParamBag();
$bag->set('foo', 'bar');
$bag->set('bar', 'baz');
$bag->remove('foo');
$this->assertEquals(['bar' => ['baz']], $bag->getArrayCopy());
}
示例3: getBackendParameters
/**
* Create search backend parameters for advanced features.
*
* @return ParamBag
*/
public function getBackendParameters()
{
$backendParams = new ParamBag();
// The "relevance" sort option is a VuFind reserved word; we need to make
// this null in order to achieve the desired effect with Primo:
$sort = $this->getSort();
$finalSort = $sort == 'relevance' ? null : $sort;
$backendParams->set('sort', $finalSort);
$backendParams->set('filterList', $this->filterList);
return $backendParams;
}
示例4: build
/**
* Return Primo search parameters based on a user query and params.
*
* @param AbstractQuery $query User query
*
* @return ParamBag
*/
public function build(AbstractQuery $query)
{
// Send back results
$params = new ParamBag();
$params->set('query', $this->abstractQueryToArray($query));
return $params;
}
示例5: getBackendParameters
/**
* Create search backend parameters for advanced features.
*
* @return ParamBag
*/
public function getBackendParameters()
{
$backendParams = new ParamBag();
// Sort
$sort = $this->getSort();
$backendParams->set('sortKeys', empty($sort) ? 'relevance' : $sort);
return $backendParams;
}
示例6: build
/**
* Return Summon search parameters based on a user query and params.
*
* @param AbstractQuery $query User query
*
* @return ParamBag
*/
public function build(AbstractQuery $query)
{
// Build base query
$queryStr = $this->abstractQueryToString($query);
// Send back results
$params = new ParamBag();
$params->set('query', $queryStr);
return $params;
}
示例7: search
/**
* Execute a search.
*
* @param ParamBag $params Parameters
* @param integer $offset Search offset
* @param integer $limit Search limit
*
* @return string
*/
public function search(ParamBag $params, $offset, $limit)
{
$params->set('startRecord', $offset);
$params->set('maximumRecords', $limit);
$params->set('servicelevel', 'full');
$params->set('wskey', $this->wskey);
$response = $this->call('POST', $params->getArrayCopy(), false);
$xml = simplexml_load_string($response);
$docs = isset($xml->records->record) ? $xml->records->record : [];
$finalDocs = [];
foreach ($docs as $doc) {
$finalDocs[] = $doc->recordData->asXML();
}
return ['docs' => $finalDocs, 'offset' => $offset, 'total' => isset($xml->numberOfRecords) ? (int) $xml->numberOfRecords : 0];
}
示例8: addUserInstitutions
/**
* Add user institutions as facet queries to backend params
*
* @param ParamBag $backendParams
*
* @return ParamBag
*/
protected function addUserInstitutions(ParamBag $backendParams)
{
/** @var Manager $favoritesManger */
$favoritesManger = $this->getServiceLocator()->get('Swissbib\\FavoriteInstitutions\\Manager');
/** @var String[] $favoriteInstitutions */
$favoriteInstitutions = $favoritesManger->getUserInstitutions();
if (sizeof($favoriteInstitutions) > 0) {
//facet parameter has to be true in case it's false
$backendParams->set("facet", "true");
foreach ($favoriteInstitutions as $institutionCode) {
//GH 19.12.2014: use configuration for index name
//more investigation for a better solution necessary
$backendParams->add("facet.query", "mylibrary:" . $institutionCode);
//$backendParams->add("bq", "institution:" . $institutionCode . "^5000");
}
}
return $backendParams;
}
示例9: createBackendFilterParameters
/**
* Set up filters based on VuFind settings.
*
* @param ParamBag $params Parameter collection to update
*
* @return void
*/
public function createBackendFilterParameters(ParamBag $params)
{
// Which filters should be applied to our query?
$filterList = $this->getFilterList();
if (!empty($filterList)) {
$orFacets = [];
// Loop through all filters and add appropriate values to request:
foreach ($filterList as $filterArray) {
foreach ($filterArray as $filt) {
$safeValue = SummonQuery::escapeParam($filt['value']);
// Special case -- "holdings only" is a separate parameter from
// other facets.
if ($filt['field'] == 'holdingsOnly') {
$params->set('holdings', strtolower(trim($safeValue)) == 'true');
} else {
if ($filt['field'] == 'queryExpansion') {
// Special case -- "query expansion" is a separate parameter
// from other facets.
$params->set('expand', strtolower(trim($safeValue)) == 'true');
} else {
if ($filt['field'] == 'excludeNewspapers') {
// Special case -- support a checkbox for excluding
// newspapers:
$params->add('filters', "ContentType,Newspaper Article,true");
} else {
if ($range = SolrUtils::parseRange($filt['value'])) {
// Special case -- range query (translate [x TO y] syntax):
$from = SummonQuery::escapeParam($range['from']);
$to = SummonQuery::escapeParam($range['to']);
$params->add('rangeFilters', "{$filt['field']},{$from}:{$to}");
} else {
if ($filt['operator'] == 'OR') {
// Special case -- OR facets:
$orFacets[$filt['field']] = isset($orFacets[$filt['field']]) ? $orFacets[$filt['field']] : [];
$orFacets[$filt['field']][] = $safeValue;
} else {
// Standard case:
$fq = "{$filt['field']},{$safeValue}";
if ($filt['operator'] == 'NOT') {
$fq .= ',true';
}
$params->add('filters', $fq);
}
}
}
}
}
}
// Deal with OR facets:
foreach ($orFacets as $field => $values) {
$params->add('groupFilters', $field . ',or,' . implode(',', $values));
}
}
}
}
示例10: injectResponseWriter
/**
* Inject response writer and named list implementation into parameters.
*
* @param ParamBag $params Parameters
*
* @return void
*
* @throws InvalidArgumentException Response writer and named list
* implementation already set to an incompatible type.
*/
protected function injectResponseWriter(ParamBag $params)
{
if (array_diff($params->get('wt') ?: [], ['json'])) {
throw new InvalidArgumentException(sprintf('Invalid response writer type: %s', implode(', ', $params->get('wt'))));
}
if (array_diff($params->get('json.nl') ?: [], ['arrarr'])) {
throw new InvalidArgumentException(sprintf('Invalid named list implementation type: %s', implode(', ', $params->get('json.nl'))));
}
$params->set('wt', ['json']);
$params->set('json.nl', ['arrarr']);
}
示例11: build
/**
* Return SOLR search parameters based on a user query and params.
*
* @param AbstractQuery $query User query
*
* @return ParamBag
*/
public function build(AbstractQuery $query)
{
$params = new ParamBag();
// Add spelling query if applicable -- note that we mus set this up before
// we process the main query in order to avoid unwanted extra syntax:
if ($this->createSpellingQuery) {
$params->set('spellcheck.q', $query->getAllTerms());
}
if ($query instanceof QueryGroup) {
$query = $this->reduceQueryGroup($query);
} else {
$query->setString($this->getLuceneHelper()->normalizeSearchString($query->getString()));
}
$string = $query->getString() ?: '*:*';
if ($handler = $this->getSearchHandler($query->getHandler(), $string)) {
if (!$handler->hasExtendedDismax() && $this->getLuceneHelper()->containsAdvancedLuceneSyntax($string)) {
$newString = $this->createAdvancedInnerSearchString($string, $handler);
if ($handler->hasDismax()) {
$oldString = $newString;
$newString = $handler->createBoostQueryString($newString);
// If a boost was added, we don't want to highlight based on
// the boost query, so we should use the non-boosted version:
if ($this->createHighlightingQuery && $oldString != $string) {
$params->set('hl.q', $oldString);
}
if ($string == '*:*') {
$params->set('hl.q', '*:*');
}
}
$string = $newString;
} else {
if ($handler->hasDismax()) {
$params->set('qf', implode(' ', $handler->getDismaxFields()));
$params->set('qt', $handler->getDismaxHandler());
foreach ($handler->getDismaxParams() as $param) {
$params->add(reset($param), next($param));
}
if ($handler->hasFilterQuery()) {
$params->add('fq', $handler->getFilterQuery());
}
} else {
$string = $handler->createSimpleQueryString($string);
}
}
}
$params->set('q', $string);
return $params;
}
示例12: getParamBag
/**
* @return ParamBag
*/
protected function getParamBag()
{
$paramBag = new ParamBag();
$paramBag->set('q', array('a'));
$paramBag->set('qf', array('title_short title_sub author series journals topic fulltext'));
$paramBag->set('qt', array('edismax'));
return $paramBag;
}
示例13: getBackendParameters
/**
* Create search backend parameters for advanced features.
*
* @return ParamBag
*/
public function getBackendParameters()
{
$backendParams = new ParamBag();
// Spellcheck
$backendParams->set('spellcheck', $this->getOptions()->spellcheckEnabled() ? 'true' : 'false');
// Facets
$facets = $this->getFacetSettings();
if (!empty($facets)) {
$backendParams->add('facet', 'true');
if (isset($facets['indexSortedFacets'])) {
foreach ($facets['indexSortedFacets'] as $field) {
$backendParams->add("f.{$field}.facet.sort", 'index');
}
unset($facets['indexSortedFacets']);
}
foreach ($facets as $key => $value) {
if (substr($key, 0, strlen(self::PER_FIELD_PARAM)) === self::PER_FIELD_PARAM) {
$backendParams->add($key, $value);
} else {
$backendParams->add("facet.{$key}", $value);
}
}
$backendParams->add('facet.mincount', 1);
}
// Filters
$filters = $this->getFilterSettings();
foreach ($filters as $filter) {
$backendParams->add('fq', $filter);
}
// Shards
$allShards = $this->getOptions()->getShards();
$shards = $this->getSelectedShards();
if (empty($shards)) {
$shards = array_keys($allShards);
}
// If we have selected shards, we need to format them:
if (!empty($shards)) {
$selectedShards = [];
foreach ($shards as $current) {
$selectedShards[$current] = $allShards[$current];
}
$shards = $selectedShards;
$backendParams->add('shards', implode(',', $selectedShards));
}
// Sort
$sort = $this->getSort();
if ($sort) {
// If we have an empty search with relevance sort, see if there is
// an override configured:
if ($sort == 'relevance' && $this->getQuery()->getAllTerms() == '' && ($relOv = $this->getOptions()->getEmptySearchRelevanceOverride())) {
$sort = $relOv;
}
$backendParams->add('sort', $this->normalizeSort($sort));
}
// Highlighting -- on by default, but we should disable if necessary:
if (!$this->getOptions()->highlightEnabled()) {
$backendParams->add('hl', 'false');
}
// Pivot facets for visual results
if ($pf = $this->getPivotFacets()) {
$backendParams->add('facet.pivot', $pf);
}
if (!empty($this->boostFunctions)) {
foreach ($this->boostFunctions as $func) {
$backendParams->add('boost', $func);
}
}
return $backendParams;
}
示例14: aggregateSpellcheck
/**
* Submit requests for more spelling suggestions.
*
* @param Spellcheck $spellcheck Aggregating spellcheck object
* @param string $query Spellcheck query
*
* @return void
*/
protected function aggregateSpellcheck(Spellcheck $spellcheck, $query)
{
while (next($this->dictionaries) !== false) {
$params = new ParamBag();
$params->set('spellcheck', 'true');
$params->set('spellcheck.dictionary', current($this->dictionaries));
$queryObj = new Query($query, 'AllFields');
try {
$collection = $this->backend->search($queryObj, 0, 0, $params);
$spellcheck->mergeWith($collection->getSpellcheck());
} catch (\Exception $ex) {
if ($this->logger) {
$this->logger->err("Exception thrown when aggregating spellcheck, ignoring.", array('exception' => $ex));
}
}
}
}
示例15: build
/**
* Return SOLR search parameters based on a record Id and params.
*
* @param string $id Record Id
*
* @return ParamBag
*/
public function build($id)
{
$params = new ParamBag();
if ($this->useHandler) {
$mltParams = $this->handlerParams ? $this->handlerParams : 'qf=title,title_short,callnumber-label,topic,language,author,' . 'publishDate mintf=1 mindf=1';
$params->set('q', sprintf('{!mlt %s}%s', $mltParams, $id));
} else {
$params->set('q', sprintf('%s:"%s"', $this->uniqueKey, addcslashes($id, '"')));
$params->set('qt', 'morelikethis');
}
if (null === $params->get('rows')) {
$params->set('rows', $this->count);
}
return $params;
}