Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[com_finder] - SQL change for removeOrphanNodes() and postgresql driver fix #12313

Merged
merged 17 commits into from
Feb 22, 2017
Merged

[com_finder] - SQL change for removeOrphanNodes() and postgresql driver fix #12313

merged 17 commits into from
Feb 22, 2017

Conversation

alikon
Copy link
Contributor

@alikon alikon commented Oct 4, 2016

Pull Request for Issue #9478 .

Summary of Changes

  • sql bug fix for the postgresql com_finder driver
  • altered fields (title, description) for #__finder_links table
  • removeOrphanNodes() sql rewrite and should be tested on MySQL/MariaDB too

Testing Instructions

  • apply the pr
  • on postgres only go to Extensions > Manage>Database - click on fix
  • enable the smart search content plugin , create/ save an article
  • index content on Smart Search: Indexed Content
  • run the cli finder_index.php script

bugfix for the postgres driver
fix for title and description fields of #__finder_links table
the title filed is varchar 400 on mysql
the descrpition need to be text
title and description fields for #__finder_links table
wrong file name
field title , description of #__finder_links table
this table does not exist
		// Optimize the terms mapping table. 
		$db->setQuery('REINDEX TABLE ' . $db->quoteName('#__finder_links_terms'));
		$db->execute();
@waader
Copy link
Contributor

waader commented Oct 5, 2016

I did a setup with latest staging, testing data and 4 additional languages. After installation I went in Extensions > Database and it gives me this message:

Table 'kp7cx_finder_links' does not have column 'description' with type text DEFAULT '' NOT NULL. (From file 3.6.3-2016-10-04.sql.)

So I pressed the Fix-Button and I got this syntax error:
Syntaxfehler bei »DEFAULT« LINE 1: ...inder_links" ALTER COLUMN "description" TYPE text DEFAULT ''... ^SQL=ALTER TABLE "#__finder_links" ALTER COLUMN "description" TYPE text DEFAULT '' NOT NULL;

So next I started the indexing process which went fine but at the end I got this syntax error:

FEHLER: Syntaxfehler bei »t« LINE 1: DELETE t FROM "#finder_taxonomy" AS t LEFT JOIN "#... ^SQL=DELETE t FROM "#__finder_taxonomy" AS t LEFT JOIN "#__finder_taxonomy_map" AS m ON m.node_id = t.id WHERE t.parent_id > 1 AND m.link_id IS NULL

Finally I did a search for "test" in the "Indexed Content" and this message appears (operator doesn´t exist: timestamp without timezone ...):

FEHLER: Operator existiert nicht: timestamp without time zone ~~ unknown LINE 4: ...t%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%te... ^ HINT: Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.SQL=SELECT l.,"t"."title" AS "t_title" FROM "#__finder_links" AS "l" INNER JOIN "#__finder_types" AS "t" ON "t"."id" = "l"."type_id" WHERE ("l"."title" LIKE '%test%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%test%') ORDER BY l.title ASC LIMIT 20 FEHLER: Operator existiert nicht: timestamp without time zone ~~ unknown LINE 4: ...t%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%te... ^ HINT: Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.SQL=SELECT COUNT() FROM "#__finder_links" AS "l" INNER JOIN "#__finder_types" AS "t" ON "t"."id" = "l"."type_id" WHERE ("l"."title" LIKE '%test%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%test%') FEHLER: Operator existiert nicht: timestamp without time zone ~~ unknown LINE 4: ...t%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%te... ^ HINT: Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.SQL=SELECT COUNT(*) FROM "#__finder_links" AS "l" INNER JOIN "#__finder_types" AS "t" ON "t"."id" = "l"."type_id" WHERE ("l"."title" LIKE '%test%' OR "l"."url" LIKE '%test%' OR "l"."indexdate" LIKE '%test%')

@alikon
Copy link
Contributor Author

alikon commented Oct 5, 2016

@waader the goals of this pr are more simple:

  1. let's run index content from Smart Search: Indexed Content
  2. let's save/create an article when the content finder plugin is enabled

a lot of more work need to be done, but this PR only affect postgresql related files so no B/C
i'll continue to work to let the com_finder workable even on Postgresql but i'll submit other PR's shortly

@waader
Copy link
Contributor

waader commented Oct 5, 2016

I understand. So I repeated the test with the same setup but without the multilingual stuff.

ad 1) let's run index content from Smart Search: Indexed Content:
This brings a syntax error at the end: FEHLER: Syntaxfehler bei »t« LINE 1: DELETE t FROM "#finder_taxonomy" AS t LEFT JOIN "#... ^SQL=DELETE t FROM "#__finder_taxonomy" AS t LEFT JOIN "#__finder_taxonomy_map" AS m ON m.node_id = t.id WHERE t.parent_id > 1 AND m.link_id IS NULL

ad 2. let's save/create an article when the content finder plugin is enabled
When saving changes made to an existing article then you get this syntax error:
Save failed with the following error: FEHLER: Syntaxfehler bei »t« LINE 1: DELETE t FROM "#finder_taxonomy" AS t LEFT JOIN "#... ^SQL=DELETE t FROM "#__finder_taxonomy" AS t LEFT JOIN "#__finder_taxonomy_map" AS m ON m.node_id = t.id WHERE t.parent_id > 1 AND m.link_id IS NULL

@alikon
Copy link
Contributor Author

alikon commented Oct 5, 2016

i'm currently investigating on it .... but i'm afraid that the needed changes to let it work at least with minimal feature should'nt be only on the Postgresql side ..... i'll updated you....

remove orphans
remove orphans
update sql fix
typo
@alikon alikon changed the title [postgresql] - com_finder index content fix [com_finder] - SQL change for removeOrphanNodes() and postgresql driver fix Oct 6, 2016
@alikon
Copy link
Contributor Author

alikon commented Oct 6, 2016

@waader can you retest ...
now the changes impact Mysql too, so should be tested

@@ -329,11 +329,15 @@ public static function removeOrphanNodes()
{
// Delete all orphaned nodes.
$db = JFactory::getDbo();
$query = 'DELETE t' .
$query = 'DELETE ' .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not make this query use JDatabaseQuery?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire thing would have to be rewritten as three query objects because there are a bunch of subqueries here.

use JDatabaseQuery
space
@alikon
Copy link
Contributor Author

alikon commented Oct 7, 2016

Can we not make this query use JDatabaseQuery?

no cause i'm lazy 😄
query rewritten using 3 JDatabaseQuery objects


$subquery1->clear()
->select($db->quoteName('t.id'))
->from($db->quoteName('#__finder_taxonomy') . ' AS t')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->from($db->quoteName('#__finder_taxonomy', 't')) 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the ON ?
->join('LEFT',$db->quoteName('#__finder_taxonomy_map', 'm') . 'ON ' ....)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think so, but care the space before ON :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

alias
alias
@@ -416,7 +416,7 @@ public function index($item, $format = 'html')
' ROUND(SUM(' . $db->quoteName('context_weight') . '), 8)' .
' FROM ' . $db->quoteName('#__finder_tokens_aggregate') .
' WHERE ' . $db->quoteName('map_suffix') . ' = ' . $db->quote($suffix) .
' GROUP BY ' . $db->quoteName('term') .
' GROUP BY ' . $db->quoteName('term') . ' ,' . $db->quoteName('term_id') .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

', ' instead of ' ,' ?

// Optimize the terms mapping table.
$db->setQuery('REINDEX TABLE ' . $db->quoteName('#__finder_links_terms'));
$db->execute();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my comment on your other PR, I think this should be #__finder_terms and so should be fixed rather than removed. Also, for completeness, there are other tables that should be optimised at the same time.

$subquery = $db->getQuery(true);
$subquery1 = $db->getQuery(true);

$subquery1->clear()
Copy link
Contributor

@chrisdavenport chrisdavenport Oct 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to call clear() here because you get a fresh query object from getQuery(true) anyway. Same for the next two statements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear removes creating a new class instance. It's performance better to call clear than to get a fresh query object

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but there's no point in calling clear on fresh query objects, which is what is being done here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops. My bad!

' AND m.link_id IS NULL';
$query = $db->getQuery(true);
$subquery = $db->getQuery(true);
$subquery1 = $db->getQuery(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I prefer the fluent style so I'd merge these three statements into the statements below.

reindex missing tables same as for mysql driver
removed unnecessary clear()
@alikon
Copy link
Contributor Author

alikon commented Oct 15, 2016

  • added the missed REINDEX
  • removed unnecessary clear()

No space found after comma in function call
@chrisdavenport
Copy link
Contributor

I have not tested this item.

I've tested with MySQL and it works fine. I haven't tested on PostGres which is why I'm not marking this as a successful test.

I created a category called "Test", then created an article in that category.
I checked that a taxonomy for the Test category had been created and the article was correctly indexed.
I deleted the article (and emptied the trash). This would trigger the removeOrphanNodes method to remove the Test category taxonomy.
I did not get any errors, the Test category taxonomy had been removed and the index had been updated correctly.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12313.

@csthomas
Copy link
Contributor

csthomas commented Feb 1, 2017

I have tested this item ✅ successfully on fe8a684

I tested successful on PostgresSQL based on test instruction. Button Index and clear index also works.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12313.

@waader
Copy link
Contributor

waader commented Feb 2, 2017

I have tested this item ✅ successfully on fe8a684

Works with postgres, thanks Alikon!

installation/sql/postgresql/joomla.sql needs an update.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12313.

@@ -0,0 +1,3 @@
ALTER TABLE "#__finder_links" ALTER COLUMN "title" TYPE character varying(400);
ALTER TABLE "#__finder_links" ALTER COLUMN "description" TYPE text;
ALTER TABLE "#__finder_links" ALTER COLUMN "description" SET NOT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about default value '' or not for description?

@infograf768
Copy link
Member

RTC as 2 good testers.

Note: last comment is
"installation/sql/postgresql/joomla.sql needs an update."


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12313.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 16, 2017
@zero-24 zero-24 added this to the Joomla 3.7.0 milestone Feb 21, 2017
@rdeutz rdeutz merged commit 7fb1491 into joomla:staging Feb 22, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 22, 2017
@alikon alikon deleted the patch-81 branch February 27, 2017 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet