本文整理汇总了PHP中Apache_Solr_Document::getFieldBoost方法的典型用法代码示例。如果您正苦于以下问题:PHP Apache_Solr_Document::getFieldBoost方法的具体用法?PHP Apache_Solr_Document::getFieldBoost怎么用?PHP Apache_Solr_Document::getFieldBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Apache_Solr_Document
的用法示例。
在下文中一共展示了Apache_Solr_Document::getFieldBoost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddFieldWithBoostMultipliesWithAPreexistingBoost
public function testAddFieldWithBoostMultipliesWithAPreexistingBoost()
{
$field = 'field';
$boost = 0.5;
// set a field with a boost
$this->_fixture->setField($field, 'value1', $boost);
// now add another value with the same boost
$this->_fixture->addField($field, 'value2', $boost);
// new boost should be $boost * $boost
$this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field));
}
示例2: _documentToXmlFragment
/**
* Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
*
* @return string
*/
protected function _documentToXmlFragment(Apache_Solr_Document $document)
{
$xml = '<doc';
if ($document->getBoost() !== false) {
$xml .= ' boost="' . $document->getBoost() . '"';
}
$xml .= '>';
foreach ($document as $key => $value) {
$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
$fieldBoost = $document->getFieldBoost($key);
if (is_array($value)) {
foreach ($value as $multivalue) {
$xml .= '<field name="' . $key . '"';
if ($fieldBoost !== false) {
$xml .= ' boost="' . $fieldBoost . '"';
// only set the boost for the first field in the set
$fieldBoost = false;
}
$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
$xml .= '>' . $multivalue . '</field>';
}
} else {
$xml .= '<field name="' . $key . '"';
if ($fieldBoost !== false) {
$xml .= ' boost="' . $fieldBoost . '"';
}
$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '>' . $value . '</field>';
}
}
$xml .= '</doc>';
// replace any control characters to avoid Solr XML parser exception
return $this->_stripCtrlChars($xml);
}
示例3: _documentToXmlFragment
/**
* Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
*
* @return string
*/
protected function _documentToXmlFragment(Apache_Solr_Document $document)
{
$xml = '<doc';
if ($document->getBoost() !== false) {
$xml .= ' boost="' . $document->getBoost() . '"';
}
$xml .= '>';
foreach ($document as $key => $value) {
$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
$fieldBoost = $document->getFieldBoost($key);
if ($key) {
if (is_array($value)) {
foreach ($value as $multivalue) {
$xml .= '<field name="' . $key . '"';
if ($fieldBoost !== false) {
$xml .= ' boost="' . $fieldBoost . '"';
// only set the boost for the first field in the set
$fieldBoost = false;
}
if (!mb_check_encoding($multivalue, 'UTF-8')) {
$multivalue = utf8_encode($multivalue);
}
$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
$xml .= '>' . $multivalue . '</field>';
}
} else {
$xml .= '<field name="' . $key . '"';
if ($fieldBoost !== false) {
$xml .= ' boost="' . $fieldBoost . '"';
}
if (!mb_check_encoding($value, 'UTF-8')) {
$value = utf8_encode($value);
}
$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '>' . $value . '</field>';
}
}
}
$xml .= '</doc>';
return $xml;
}