English > Install & Configure jDiction
Searching with finder
Finarfin:
Sorry, you are right, It will have problems only if you have articles with language different than "*"
Harald Leithner:
Untested but tries this function:
--- Code: ---protected function getContentCount() {
$jDiction = jDiction::getInstance();
$languages = $jDiction->getLanguages(true);
$return = 0;
// Get the list query.
$query = $this->getListQuery();
// Check if the query is valid.
if (empty($query)) {
return $return;
}
// we don't support non JDatabaseQueries here atm
if ($query instanceof JDatabaseQuery) {
return parent::getContentCount();
}
$columns = $this->db->getTableColumns($this->table);
if (array_key_exists('language', $columns)) {
$query = clone($query);
$query->clear('select')
->select('COUNT(*)')
->clear('order');
// Get the total number of content items per language to index.
foreach($languages as $language) {
$querylang = clone($query);
$querylang->where('a.language = '.$this->db->q($language->lang_code));
$this->db->setQuery($querylang);
$return += (int) $this->db->loadResult();
}
}
$querylang = clone($query);
// Get the total number of content items translated languages to index.
$querylang->where('a.language = '.$this->db->q('*'));
$this->db->setQuery($querylang);
$return += ((int) $this->db->loadResult() * count($languages));
return $return;
}
--- End code ---
Finarfin:
Almost perfect :D
Two points
Why the if ($query instanceof JDatabaseQuery) ? I don´t know why, but with that if it calls the parent and so give the bad number. I don´t know why is that the check, but I disable it for testing and worked. Perfectly! :O
Another topic, I guess that this
$querylang = clone($query);
// Get the total number of content items translated languages to index.
$querylang->where('a.language = '.$this->db->q('*'));
$this->db->setQuery($querylang);
$return += ((int) $this->db->loadResult() * count($languages));
have to be inside the if (array_key_exists('language', $columns)) {, but is a not really a big deal.
Another thing
Inside the getItems, you have to divide the offset between count(languages). Why? Because you are returning count(language)*number of items, but the table you are visiting is not queried as fast.
Example
Offset = 0
Limit = 60
getItems()
- select from 0 to 60 (for jdiction I will get 180)
Offset = 180
Limit = 60
here, if I do the select from 180 with a 60 limit, I´m leaving behind the entries between 60 and 180 so... I have to divide.
And that´s all for today. I want to clean my code, maybe do some tests more and I´ll be able to try to compilate the patches done so you have them available.
Regards and thanks for your help, that last function, saved me :P
Harald Leithner:
You are right this function should work better:
--- Code: ---protected function getContentCount() {
$jDiction = jDiction::getInstance();
$languages = $jDiction->getLanguages(true);
$return = 0;
// Get the list query.
$query = $this->getListQuery();
// Check if the query is valid.
if (empty($query)) {
return $return;
}
// we don't support non JDatabaseQueries here atm
if (!$query instanceof JDatabaseQuery) {
return parent::getContentCount();
}
$columns = $this->db->getTableColumns($this->table);
if (array_key_exists('language', $columns)) {
$query = clone($query);
$query->clear('select')
->select('COUNT(*)')
->clear('order');
// Get the total number of content items per language to index.
foreach($languages as $language) {
$querylang = clone($query);
$querylang->where('a.language = '.$this->db->q($language->lang_code));
$this->db->setQuery($querylang);
$return += (int) $this->db->loadResult();
}
// Get the total number of content items translated languages to index.
$query->where('a.language = '.$this->db->q('*'));
}
$this->db->setQuery($query);
$return += ((int) $this->db->loadResult() * count($languages));
return $return;
}
--- End code ---
The Problem with the offset is that onBuildIndex calculates the batchOffset based on the rows it gets and not on the offset it gives me, jDictions returns more rows then expected...
I'm not sure how to solve this. Maybe by changing the onBuildIndex from:
--- Code: --- // Adjust the offsets.
$offset++;
$iState->batchOffset++;
$iState->totalItems--;
--- End code ---
to
--- Code: ---
// after the for loop
$offset += $offset;
$iState->batchOffset += $offset;
$iState->totalItems -= $offset;
--- End code ---
but this would fail if we return less $items then offset... maybe changing this to count($items) if $offset is less then count($items).
Harald Leithner:
Maybe this override could fix the count problem.
--- Code: --- public function onBuildIndex()
{
// Get the indexer and adapter state.
$iState = FinderIndexer::getState();
$aState = $iState->pluginState[$this->context];
// Check the progress of the indexer and the adapter.
if ($iState->batchOffset == $iState->batchSize || $aState['offset'] == $aState['total'])
{
return true;
}
// Get the batch offset and size.
$offset = (int) $aState['offset'];
$limit = (int) ($iState->batchSize - $iState->batchOffset);
// Get the content items to index.
$items = $this->getItems($offset, $limit);
// Iterate through the items and index them.
for ($i = 0, $n = count($items); $i < $n; $i++)
{
// Index the item.
$this->index($items[$i]);
}
// Adjust the offsets.
if ($limit > count($items)) {
$limit = count($items);
}
$offset += $limit;
$iState->batchOffset += $limit;
$iState->totalItems -= $limit;
// Update the indexer state.
$aState['offset'] = $offset;
$iState->pluginState[$this->context] = $aState;
FinderIndexer::setState($iState);
return true;
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version