php-general Digest 25 Jan 2011 11:32:58 -0000 Issue 7151

Topics (messages 311008 through 311011):

Re: Zend memory manager
        311008 by: Daniel Brown
        311009 by: Adi Mutu

Re: Mysql search query ignoring dots
        311010 by: Tom Rogers

Re: preg_replace question
        311011 by: Merlin Morgenstern

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Mon, Jan 24, 2011 at 14:17, Adi Mutu <adi_mut...@yahoo.com> wrote:
>
> I have asked also there......but no answer....But honestly i don't understand 
> why you have reccomended me that forum......because i thougt these mailing 
> lists are about php developing.......

    Because this is about developing in PHP in general, not what makes
PHP work.  You don't seem to be making the distinction.  To clarify,
again:

        This is not the place to ask.

    At best, you could use the Internals mailing list, but to be
perfectly honest, I doubt you'll get the help you're seeking with what
you've asked.  Still, you can try: intern...@lists.php.net.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--- End Message ---
--- Begin Message ---

Ok, Everything's clear now.Thanks for the help and sorry for incoveniences.




      

--- End Message ---
--- Begin Message ---
Hi,

Monday, January 24, 2011, 10:50:41 PM, you wrote:
BP> Hi all,

BP> I have to perform a mysql query in a table with millions of records.
BP> I've full-text indexed my search field and I'm searching with MATCH AGAINST.
BP> But there is a problem. In this field there are company names that 
BP> contain dots, for istance I've "PO.SE. srl" and I want to find it if 
BP> the user search for: "POSE" or "PO.SE" or "P.O.S.E." etc.
BP> I googled in the web but I don't find any solution. I don't want to 
BP> add a new field with the cleaned version of my string because I would 
BP> like to solve with the query and I prefer that the mysql table not 
BP> become too big. But if I will not find a different solution, I will 
BP> use this escamotage.
BP> I've find a post that is similar but the solution don't seem to solve 
BP> my situation.
BP> You can see it at the url:
BP> http://forums.mysql.com/read.php?10,395557,395584#msg-395584
BP> In my case replace(email, '.', '') = replace(theSearchValue, '.', '');
BP> is indifferent and don't change my results.

BP> My query, searching "POSE", is:

BP> select aziende.* from aziende where 1>0 AND 
BP> (MATCH(aziende.ragione_sociale) AGAINST('+POSE' IN BOOLEAN MODE) OR 
BP> (replace(aziende.ragione_sociale, '.', '') = replace('POSE', '.', 
BP> '')) order by aziende.ragione_sociale limit 0, 10

BP> The alternative choice could be REGEXP but I've red that it make my 
BP> query slow in a table of millions of records and I don't know how to 
BP> exclude dots in the regular expression.

BP> Can anyone help me?

BP> Thanks in advance.
BP> Barbara

BP> -- 
BP> ------------------------
BP> Barbara Picci
BP> Micro srl
BP> viale Marconi 222, 09131 Cagliari  - tel. (+39) 070400240
BP> http://www.microsrl.com


In  the interest of speed it may be worth creating a table with just a
link id and the text to search which you can cleanup before inserting.
It will probably save you a headache in the future and will be quicker
than complicated queries.

The list of possible ids can then be tested against the full table for
any other criteria which if the table is indexed properly will be fast
too.

-- 
regards,
Tom


--- End Message ---
--- Begin Message ---
Am 24.01.2011 18:08, schrieb Alex Nikitin:
If you declare your arrays, and set k to 0 first, put quotes around array
values and use the correct limit (you can default to -1), you will get
results, here is code and example (hopefully this helps you)


<?php
        function internal_links($str, $links, $limit=-1) {
                $pattern=array();
                $replace=array();
                $k=0;
                foreach($links AS $link){
                        $pattern[$k] = "~\b({$link['phrase']})\b~i";
                        $replace[$k] = '<a href="'.$link['link'].'">\\1</a>';
                        $k++;
                }
                return preg_replace($pattern,$replace,$str, $limit);
        }

echo internal_links("süße knuffige Beagle Welpen ab sofort",
array(array('phrase'=>"beagle",
'link'=>"http://google.com";),array('phrase'=>"welpen",
'link'=>"http://wolframalpha.com";)), -1);

Output:
süße knuffige<a href="http://google.com";>Beagle</a>  <a href="
http://wolframalpha.com";>Welpen</a>  ab

~Alex


Hello,

thank you all for your help. It seems that I am building the array wrong. Your code works with that array:

$internal_links = array(array('phrase'=>"beagle", 'link'=>"http://google.com";),array('phrase'=>"welpen", 'link'=>"http://wolframalpha.com";));

I am pulling the data out of a DB and am using this code:
        while ($row = mysql_fetch_object($result)){             
                $internal_links[$row->ID]['phrase'] = $row->phrase;
                $internal_links[$row->ID]['link'] = $row->link;
        }       

You build the array different, could you help me to adapt this on my code? I tried $internal_links['phrase'][] as well, but that did not help either.

Thank you for any help,

Merlin

--- End Message ---

Reply via email to