Bumpity bump, trying it again, Tom/Dan, could you have a look at this
thread? Seems to me like quite important thing.
Thanks
Vasik
On 5 led, 00:05, Vasik Greif <
vaclav.gr...@gmail.com> wrote:
> Thanks! Tom & Dan, could you have a look at this?
>
> Vasik
>
> On 4 led, 23:39, Paul Manno <
pgma...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Updated step 1 to exclude any keywords in collection_keywords table
>
> > Step 1: Findallkeywords attached to this resource ($ref), then of those
> > keywords, find those that are referenced once (this is a fairly costly
> > query and research should be done to optimize the indexing to support it).
>
> > $keywords = sql_query("select keyword, count(*) from resource_keyword where
> > keyword in (select distinct keyword from resource_keyword where
> > resource='$ref') and not exists (select 'x' from collection_keyword where
> > resource_keyword.keyword = collection_keyword.keyword) group by keyword
> > having count(*) =1");
>
> > Step 2: Now we have an array of keywords that are only referenced once, so
> > we can assume that this resource is the only resource touching these
> > keywords, so we candeletethem.
>
> > foreach($keywords as $keyword)
> > {
> > sql_query("deletefrom keyword where ref=$keyword[0]");
>
> > }
>
> > Step 3:Deletethe rows in resource_keyword for this resource.
> > sql_query("deletefrom resource_keyword where resource='$ref' and not
> > exists (select 'x' from collection_keyword where
> > collection_keyword.keyword=resource_keyword.keyword)");
>
> > Step 4:Deletethe resource, which I think there is a function for already
> > (and it may do step 3 already also).
>
> > On Wed, Jan 4, 2012 at 4:22 PM, Vasik Greif <
vaclav.gr...@gmail.com> wrote:
> > > Could you update the query to take collection_keyword into account
> > > too? I think the logic should be if the keyword is referenced once
> > > only in the resource_keyword table and is not referenced in the
> > > collection_keyword table, thandeleteit, right?
>
> > > Thanks
> > > Vasik
>
> > > On 4 led, 23:09, Paul Manno <
pgma...@gmail.com> wrote:
> > > > Yes, you are right. The collection_keyword table should be looked at too
> > > > before deleting the keyword.
>
> > > > On Wed, Jan 4, 2012 at 3:56 PM, Vasik Greif <
vaclav.gr...@gmail.com>
> > > wrote:
> > > > > Looks great, and is much better than what I did, thanks! Other
> > > > > question is on the collection_keyword table, maybe we should take into
> > > > > account that one too?
>
> > > > > Thanks
> > > > > Vasik
>
> > > > > On 4 led, 22:42, Paul Manno <
pgma...@gmail.com> wrote:
> > > > > > Step 1: Findallkeywords attached to this resource ($ref), then of
> > > those
> > > > > > keywords, find those that are referenced once (this is a fairly
> > > costly
> > > > > > query and research should be done to optimize the indexing to support
> > > > > it).
>
> > > > > > $keywords = sql_query("select keyword, count(*) from resource_keyword
> > > > > where
> > > > > > keyword in (select distinct keyword from resource_keyword where
> > > > > > resource='$ref') group by keyword having count(*) =1");
>
> > > > > > Step 2: Now we have an array of keywords that are only referenced
> > > once,
> > > > > so
> > > > > > we can assume that this resource is the only resource touching these
> > > > > > keywords, so we candeletethem.
>
> > > > > > foreach($keywords as $keyword)
> > > > > > {
> > > > > > sql_query("deletefrom keyword where ref=$keyword[0]");
>
> > > > > > }
>
> > > > > > Step 3:Deletethe rows in resource_keyword for this resource.
> > > > > > sql_query("deletefrom resource_keyword where resource='$ref'");
>
> > > > > > Step 4:Deletethe resource, which I think there is a function for
> > > > > already
> > > > > > (and it may do step 3 already also).
>
> > > > > > On Wed, Jan 4, 2012 at 12:15 PM, Vasik Greif <
vaclav.gr...@gmail.com
>
> > > > > wrote:
> > > > > > > Aaaah, right, my check was wrong, I was checking in wrong table,
> > > heres
> > > > > > > another take, please let me know what do you think
>
> > > > > > > $keywords_to_delete = sql_query("select from resource_keyword where
> > > > > > > resource='$ref'");
> > > > > > > $keyword_refs = mysql_fetch_array($keywords_to_delete);
> > > > > > > foreach($keyword_refs as $keyword_ref)
> > > > > > > {
> > > > > > > $result = sql_query("select resource from resource_keyword
> > > > > where
> > > > > > > keyword='$keyword_ref'");
>
> > > > > > > if (!$result){
> > > > > > > sql_query("deletefrom keyword where