本文整理汇总了PHP中Zend_Search_Lucene_Field::binary方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Field::binary方法的具体用法?PHP Zend_Search_Lucene_Field::binary怎么用?PHP Zend_Search_Lucene_Field::binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Field
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Field::binary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* php index.php db index
*
*/
public function index()
{
$query = "SELECT * FROM Products AS p JOIN Categories AS c ON p.CategoryID = c.CategoryId JOIN Suppliers AS s ON p.SupplierID = s.SupplierID";
$stmt = $this->db->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$indexDir = APP_PATH . '/' . self::INDEX_DIR;
is_dir($indexDir) || mkdir($indexDir, 0777, true);
$index = self::create($indexDir);
foreach ($rows as $row) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::keyword('ProductName', $row['ProductName']));
$doc->addField(Zend_Search_Lucene_Field::text('Quantity', $row['QuantityPerUnit']));
$doc->addField(Zend_Search_Lucene_Field::keyword('Category', $row['CategoryName']));
$doc->addField(Zend_Search_Lucene_Field::unIndexed('Description', $row['Description']));
$doc->addField(Zend_Search_Lucene_Field::unStored('City', $row['City']));
$doc->addField(Zend_Search_Lucene_Field::keyword('CompanyName', $row['CompanyName']));
$doc->addField(Zend_Search_Lucene_Field::binary('Picture', $row['Picture']));
$index->addDocument($doc);
}
}
示例2: addToIndex
/**
* addToIndex
* @param string $strIndexPath
* @param string $strKey
* @author Thomas Schedler <tsh@massiveart.com>
* @version 1.0
*/
protected final function addToIndex($strIndexPath, $strKey)
{
try {
if (!is_object($this->objIndex) || !$this->objIndex instanceof Zend_Search_Lucene) {
if (count(scandir($strIndexPath)) > 2) {
$this->objIndex = Zend_Search_Lucene::open($strIndexPath);
} else {
$this->objIndex = Zend_Search_Lucene::create($strIndexPath);
}
}
$objDoc = new Zend_Search_Lucene_Document();
$objDoc->addField(Zend_Search_Lucene_Field::keyword('key', $strKey));
$objDoc->addField(Zend_Search_Lucene_Field::unIndexed('date', $this->setup->getPublishDate('d.m.Y')));
$objDoc->addField(Zend_Search_Lucene_Field::unIndexed('rootLevelId', $this->setup->getRootLevelId()));
/**
* index fields
*/
foreach ($this->setup->FieldNames() as $strField => $intFieldType) {
$objField = $this->setup->getField($strField);
if (is_object($objField) && $objField->idSearchFieldTypes != Search::FIELD_TYPE_NONE) {
$strValue = '';
if (is_array($objField->getValue()) && $objField->sqlSelect != '') {
$arrIds = $objField->getValue();
$sqlSelect = $objField->sqlSelect;
if (is_array($arrIds)) {
if (count($arrIds) > 0) {
$strReplaceWhere = '';
foreach ($arrIds as $strId) {
$strReplaceWhere .= $strId . ',';
}
$strReplaceWhere = trim($strReplaceWhere, ',');
$objReplacer = new Replacer();
$sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
$objCategoriesData = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
if (count($objCategoriesData) > 0) {
foreach ($objCategoriesData as $objCategories) {
$strValue .= $objCategories->title . ', ';
}
$strValue = rtrim($strValue, ', ');
}
}
}
} else {
$strValue = $objField->getValue();
}
if ($strValue != '') {
switch ($objField->idSearchFieldTypes) {
case Search::FIELD_TYPE_KEYWORD:
$objDoc->addField(Zend_Search_Lucene_Field::keyword($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_UNINDEXED:
$objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_BINARY:
$objDoc->addField(Zend_Search_Lucene_Field::binary($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_TEXT:
$objDoc->addField(Zend_Search_Lucene_Field::text($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_UNSTORED:
$objDoc->addField(Zend_Search_Lucene_Field::unStored($strField, strip_tags($strValue), $this->core->sysConfig->encoding->default));
break;
}
}
}
}
// Add document to the index.
$this->objIndex->addDocument($objDoc);
$this->objIndex->optimize();
} catch (Exception $exc) {
$this->core->logger->err($exc);
}
}
示例3: indexFieldNow
/**
* indexFieldNow
* @param GenericElementField $objField
* @param string $strField
* @param integer $intFieldType
* @param string|array|object $mixedFieldValue
* @param Zend_Search_Lucene_Document $objDoc
* @return void
* @author Thomas Schedler <tsh@massiveart.com>
*/
protected final function indexFieldNow($objField, $strField, $intFieldType, $mixedFieldValue, Zend_Search_Lucene_Document &$objDoc)
{
try {
$strValue = '';
$strValueIds = '';
if ($objField->typeId == GenericSetup::FIELD_TYPE_ID_TAG) {
$mixedValue = $mixedFieldValue;
if (is_object($mixedValue) || is_array($mixedValue)) {
foreach ($mixedValue as $objTag) {
$strValue .= $objTag->title . ', ';
$strValueIds .= '[' . $objTag->id . ']';
}
$strValue = rtrim($strValue, ', ');
}
} elseif (!is_object($mixedFieldValue) && $objField->sqlSelect != '') {
$sqlSelect = $objField->sqlSelect;
$arrIds = array();
if (is_array($mixedFieldValue)) {
$arrIds = $mixedFieldValue;
} else {
if ($mixedFieldValue != '') {
if (strpos($mixedFieldValue, '[') !== false) {
$mixedFieldValue = trim($mixedFieldValue, '[]');
$arrIds = explode('][', $mixedFieldValue);
} else {
$arrIds = array($mixedFieldValue);
}
}
}
if (is_array($arrIds)) {
if (count($arrIds) > 0) {
$strReplaceWhere = '';
foreach ($arrIds as $strId) {
$strReplaceWhere .= $strId . ',';
}
$strReplaceWhere = trim($strReplaceWhere, ',');
$objReplacer = new Replacer();
$sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
$objCategoriesData = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
if (count($objCategoriesData) > 0) {
foreach ($objCategoriesData as $objCategories) {
$strValue .= $objCategories->title . ', ';
$strValueIds .= '[' . $objCategories->id . ']';
}
$strValue = rtrim($strValue, ', ');
}
}
}
} else {
$strValue = html_entity_decode($mixedFieldValue, ENT_COMPAT, $this->core->sysConfig->encoding->default);
}
if (is_string($strValue) && $strValue != '') {
if ($intFieldType == GenericSetup::FILE_FIELD) {
$objFiles = $this->getModelFiles()->loadFilesById($strValue);
$arrValues = array();
if (count($objFiles) > 0) {
foreach ($objFiles as $objFile) {
$arrValues[] = array('path' => $objFile->path, 'filename' => $objFile->filename, 'version' => $objFile->version);
}
}
$strValueIds = $strValue;
$strValue = serialize($arrValues);
}
if ($strValueIds != '') {
$objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField . 'Ids', $strValueIds, $this->core->sysConfig->encoding->default));
}
$this->core->logger->debug($strField . ': ' . $strValue);
switch ($objField->idSearchFieldTypes) {
case Search::FIELD_TYPE_KEYWORD:
$objDoc->addField(Zend_Search_Lucene_Field::keyword($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_UNINDEXED:
$objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_BINARY:
$objDoc->addField(Zend_Search_Lucene_Field::binary($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_TEXT:
$objDoc->addField(Zend_Search_Lucene_Field::text($strField, $strValue, $this->core->sysConfig->encoding->default));
break;
case Search::FIELD_TYPE_UNSTORED:
$objDoc->addField(Zend_Search_Lucene_Field::unStored($strField, strip_tags($strValue), $this->core->sysConfig->encoding->default));
break;
}
}
} catch (Exception $exc) {
$this->core->logger->err($exc);
}
}
示例4: normalizeMap
/**
* converts the map into a document so Lucene can save it
*
* @param MingoTable $table
* @param array $map the raw map passed to {@link insert()} or {@link update()}
* @return Zend_Search_Lucene_Document
*/
protected function normalizeMap(MingoTable $table, array $map)
{
$document = new Zend_Search_Lucene_Document();
// add some fields that will be present in all documents...
$document->addField(Zend_Search_Lucene_Field::unStored('_id', $map['_id']));
$document->addField(Zend_Search_Lucene_Field::binary('body', $this->getBody($map)));
// add all the indexes into the document...
foreach ($table->getIndexes() as $index) {
foreach ($index->getFields() as $name => $options) {
// use array_key... to account for null values...
if (array_key_exists($name, $map)) {
$val = null;
if (is_array($map[$name])) {
$val = join(' ', $map[$name]);
} else {
$val = $map[$name];
}
//if/else
$document->addField(Zend_Search_Lucene_Field::UnStored($name, $val));
// let's not try and add it twice...
unset($map[$name]);
}
//if
}
//foreach
}
//foreach
return $document;
}