Author: david
Date: Mon Feb 20 12:52:50 2012
New Revision: 10946
Log:
Use single static variable for cached PDO statements. Add subject & place
terms to QubitSearchPdo
Modified:
trunk/lib/QubitSearch.class.php
trunk/lib/QubitSearchPdo.class.php
Modified: trunk/lib/QubitSearch.class.php
==============================================================================
--- trunk/lib/QubitSearch.class.php Mon Feb 20 12:05:48 2012 (r10945)
+++ trunk/lib/QubitSearch.class.php Mon Feb 20 12:52:50 2012 (r10946)
@@ -28,7 +28,7 @@
protected static
$_instance,
$conn,
- $creationEventStatement;
+ $statements;
public static function getInstance()
{
@@ -683,7 +683,7 @@
$creatorLinks = array();
$histories = array();
- if (!isset(self::$creationEventStatement))
+ if (!isset(self::$statements['creationEvent']))
{
$sql = 'SELECT
event.id,
@@ -706,16 +706,16 @@
AND i18n.culture = ?
AND act_i18n.culture = ?';
- self::$creationEventStatement = self::$conn->prepare($sql);
+ self::$statements['creationEvent'] = self::$conn->prepare($sql);
}
- self::$creationEventStatement->execute(array(
+ self::$statements['creationEvent']->execute(array(
$informationObjectId,
QubitTerm::CREATION_ID,
$culture,
$culture));
- foreach (self::$creationEventStatement->fetchAll(PDO::FETCH_OBJ) as $item)
+ foreach (self::$statements['creationEvent']->fetchAll(PDO::FETCH_OBJ) as
$item)
{
if (isset($item->date) || isset($item->start_date) ||
isset($item->end_date))
{
Modified: trunk/lib/QubitSearchPdo.class.php
==============================================================================
--- trunk/lib/QubitSearchPdo.class.php Mon Feb 20 12:05:48 2012 (r10945)
+++ trunk/lib/QubitSearchPdo.class.php Mon Feb 20 12:52:50 2012 (r10946)
@@ -25,8 +25,7 @@
protected static
$infoObjectCount,
$levelsOfDescription,
- $startTime,
- $statement;
+ $startTime;
public function qubitPopulate($options)
{
@@ -130,7 +129,7 @@
public function indexInformationObjects($ancestors, $options = array())
{
// Cache the select statement
- if (!isset(self::$statement))
+ if (!isset(self::$statements['informationObjects']))
{
// Get info objects (with offset)
$sql = 'SELECT
@@ -154,7 +153,7 @@
$sql .= ' ORDER BY io.lft';
//$sql .= ' LIMIT '.$offset.', '.$limit;
- self::$statement = self::$conn->prepare($sql);
+ self::$statements['informationObjects'] = self::$conn->prepare($sql);
}
if (0 < count($ancestors))
@@ -166,11 +165,11 @@
$parentId = QubitInformationObject::ROOT_ID;
}
- self::$statement->execute(array(
+ self::$statements['informationObjects']->execute(array(
':parentId' => $parentId,
':pubStatusTypeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID));
- foreach (self::$statement->fetchAll(PDO::FETCH_OBJ) as $i => $resource)
+ foreach (self::$statements['informationObjects']->fetchAll(PDO::FETCH_OBJ)
as $i => $resource)
{
$this->counter++;
$thisOptions = $options;
@@ -345,22 +344,13 @@
// CREATION DATES AND CREATORS
$doc = self::addCreationEvents($doc, $resource->id, $resource->culture);
+ // SUBJECT AND PLACE ACCESS POINTS
+ $doc = self::addSubjectsAndPlaces($doc, $resource->id, $resource->culture);
+
self::getInstance()->getEngine()->getIndex()->addDocument($doc);
return;
- // Subjects
- $subjectField = Zend_Search_Lucene_Field::Unstored('subject',
$resource->getAccessPointsString(QubitTaxonomy::SUBJECT_ID, array('culture' =>
$language)));
- // Boost the hit relevance for the subject field
- $subjectField->boost = 5;
- $doc->addField($subjectField);
-
- // Place
- $placeField = Zend_Search_Lucene_Field::Unstored('place',
$resource->getAccessPointsString(QubitTaxonomy::PLACE_ID, array('culture' =>
$language)));
- // Boost the hit relevance for the place field
- $placeField->boost = 3;
- $doc->addField($placeField);
-
// Names
$nameField = Zend_Search_Lucene_Field::Unstored('name',
$resource->getNameAccessPointsString(array('culture' => $language)));
// Boost the hit relevance for the place field
@@ -477,4 +467,68 @@
return self::$levelsOfDescription[$id]->getName(array('culture' =>
$culture));
}
}
+
+ protected static function addSubjectsAndPlaces($doc, $informationObjectId,
$culture)
+ {
+ $subject = $places = array();
+
+ if (!isset(self::$statements['subjectsPlaces']))
+ {
+ $sql = 'SELECT
+ term.taxonomy_id,
+ i18n.name';
+ $sql .= ' FROM '.QubitObjectTermRelation::TABLE_NAME.' otr';
+ $sql .= ' JOIN '.QubitTerm::TABLE_NAME.' term
+ ON otr.term_id = term.id';
+ $sql .= ' JOIN '.QubitTermI18n::TABLE_NAME.' i18n
+ ON term.id = i18n.id';
+ $sql .= ' WHERE otr.object_id = ?
+ AND i18n.culture = ?
+ AND (term.taxonomy_id = ?
+ OR term.taxonomy_id = ?)';
+
+ self::$statements['subjectsPlaces'] = self::$conn->prepare($sql);
+ }
+
+ self::$statements['subjectsPlaces']->execute(array(
+ $informationObjectId,
+ $culture,
+ QubitTaxonomy::SUBJECT_ID,
+ QubitTaxonomy::PLACE_ID));
+
+ foreach (self::$statements['subjectsPlaces']->fetchAll(PDO::FETCH_OBJ) as
$item)
+ {
+ switch ($item->taxonomy_id)
+ {
+ // Subject
+ case QubitTaxonomy::SUBJECT_ID:
+ $subjects[] = $item->name;
+ break;
+
+ // Place
+ case QubitTaxonomy::PLACE_ID:
+ $places[] = $item->name;
+ break;
+
+ }
+
+ if (0 < count($subjects))
+ {
+ $subjectField = Zend_Search_Lucene_Field::Unstored('subject',
implode(' ', $subjects));
+ // Boost the hit relevance for the subject field
+ $subjectField->boost = 5;
+ $doc->addField($subjectField);
+ }
+
+ if (0 < count($places))
+ {
+ $placeField = Zend_Search_Lucene_Field::Unstored('place', implode(' ',
$places));
+ // Boost the hit relevance for the place field
+ $placeField->boost = 3;
+ $doc->addField($placeField);
+ }
+ }
+
+ return $doc;
+ }
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.