如何用PHP在solr中索引和搜索数组

如何用PHP在solr中索引和搜索数组,php,solr,cakephp-2.0,solr4,Php,Solr,Cakephp 2.0,Solr4,在我们的CakePHP应用程序中,我们有这样一个数组: Array ( [0] => Array ( [Event] => Array ( [id] => 1 [org_id] => 1 [name] => Troubadour

在我们的CakePHP应用程序中,我们有这样一个数组:

Array
(
    [0] => Array
        (
            [Event] => Array
                (
                    [id] => 1
                    [org_id] => 1
                    [name] => Troubadour
                    [url_seo] => think-alone
                    [description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
                    [category_id] => 1
                    [sub_category_id] => 1
                    [special_offer] => yes
                    [capacity] => 100
                    [visibility] => E
                    [location] => Old National Centre     502 North New Jersey St Indianapolis, IN, 46204
                    [address] => Old National Centre      502 North New Jersey St Indianapolis, IN, 46204
                    [city] => Indianapolis
                    [state] => WA
                    [country] => US
                    [zipcode] => 98828 
                    [fb_url] => https://www.facebook.com/Think Alone
                    [twitter_url] => https://www.twitter.com/Think Alone
                    [status] => A
                    [featured] => Y
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Organization] => Array
                (
                    [id] => 1
                    [user_id] => 2
                    [name] =>  test org
                    [company_profile] => We are a company built on integrity
                    [motto] => Engineering Knowledge
                    [logo] => 
                    [website] => http://www. test org.com/
                    [subdomain] => 
                    [timezone] => 
                    [currency] => 
                    [video_link] => 
                    [company_email] => info@ test org.com
                    [contact_address] =>  test org Technologies. 4th and 5th floor,  Asset Iris Building, N F Gate Main Road, Tripunithura, Cochin,  India    - 682 301
                    [contact_phone] => + 91 484 2785 833
                    [contact_mobile] => 
                    [city] => Cochin
                    [state] => Ernakulam
                    [country] => india
                    [zipcode] => 682 301
                    [email_notification] => 1
                    [fb_url] => https://www.facebook.com/ test org
                    [twitter_url] => https://www.twitter.com/ test org
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Category] => Array
                (
                    [id] => 1
                    [name] => Business
                    [image] => 
                    [category_code] => business
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [SubCategory] => Array
                (
                    [id] => 1
                    [category_id] => 1
                    [name] => Advertising & Marketing 
                    [image] => 
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [EventDate] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [start_date] => 2013-09-21
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-22
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 9
                            [event_id] => 1
                            [start_date] => 2013-09-23
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-24
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-19 00:00:00
                            [modified] => 2013-09-19 00:00:00
                        )

                    [2] => Array
                        (
                            [id] => 7
                            [event_id] => 1
                            [start_date] => 2013-09-27
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-28
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-18 00:00:00
                            [modified] => 2013-09-18 00:00:00
                        )

                    [3] => Array
                        (
                            [id] => 14
                            [event_id] => 1
                            [start_date] => 2013-09-29
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-30
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-25 00:00:00
                            [modified] => 2013-09-25 00:00:00
                        )

                    [4] => Array
                        (
                            [id] => 6
                            [event_id] => 1
                            [start_date] => 2013-10-15
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-10-15
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-18 00:00:00
                            [modified] => 2013-09-18 00:00:00
                        )

                )

            [EventMedia] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [image_url] => upcom-img1.jpg
                            [video_url] => 
                            [created] => 2013-09-25 00:00:00
                            [modified] => 2013-09-25 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 6
                            [event_id] => 1
                            [image_url] => upcom-img4.jpg
                            [video_url] => 
                            [created] => 0000-00-00 00:00:00
                            [modified] => 0000-00-00 00:00:00
                        )

                )

            [EventTicket] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [name] => VIP Early Bird Experience
                            [inventory] => 60
                            [pricing] => P
                            [price] => 30
                            [more_info] => It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable Eng
                            [sale_start_date] => 2013-09-15
                            [sale_start_time] => 10.00 AM
                            [sale_end_date] => 2013-09-20
                            [sale_end_time] => 5.00 PM
                            [min_tickets_per_order] => 1
                            [max_tickets_per_order] => 1
                            [ticket_series] => 1_1000
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [event_id] => 1
                            [name] => Craft Beer Heaven
                            [inventory] => 40
                            [pricing] => P
                            [price] => 20
                            [more_info] => It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable Eng
                            [sale_start_date] => 2013-09-16
                            [sale_start_time] => 10.00 AM
                            [sale_end_date] => 2013-09-20
                            [sale_end_time] => 5.00 PM
                            [min_tickets_per_order] => 1
                            [max_tickets_per_order] => 1
                            [ticket_series] => 1_1061
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                )

        )

    [1] => Array
        (
            [Event] => Array
                (
                    [id] => 10
                    [org_id] => 1
                    [name] => Music Night
                    [url_seo] => music-night
                    [description] => Contrary to popular belief, Lorem Ipsum is not simply random text. 
                    [category_id] => 2
                    [sub_category_id] => 3
                    [special_offer] => no
                    [capacity] => 30
                    [visibility] => E
                    [location] => Los Angeles
                    [address] => The Echo     1822 W Sunset Blvd Los Angeles, California, 90026
                    [city] => Los Angeles
                    [state] => California
                    [country] => US
                    [zipcode] => 90026
                    [fb_url] => http://www.facebook.com/music-night
                    [twitter_url] => http://www.twitter.com/music-night
                    [status] => A
                    [featured] => N
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Organization] => Array
                (
                    [id] => 1
                    [user_id] => 2
                    [name] =>  test org
                    [company_profile] => We are a company built on integrity
                    [motto] => Engineering Knowledge
                    [logo] => 
                    [website] => http://www. test org.com/
                    [subdomain] => 
                    [timezone] => 
                    [currency] => 
                    [video_link] => 
                    [company_email] => info@ test org.com
                    [contact_address] =>  test org Technologies. 4th and 5th floor,  Asset Iris Building, N F Gate Main Road, Tripunithura, Cochin,  India    - 682 301
                    [contact_phone] => + 91 484 2785 833
                    [contact_mobile] => 
                    [city] => Cochin
                    [state] => Ernakulam
                    [country] => india
                    [zipcode] => 682 301
                    [email_notification] => 1
                    [fb_url] => https://www.facebook.com/ test org
                    [twitter_url] => https://www.twitter.com/ test org
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Category] => Array
                (
                    [id] => 2
                    [name] => Music & nightlife
                    [image] => 
                    [category_code] => music
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [SubCategory] => Array
                (
                    [id] => 3
                    [category_id] => 2
                    [name] => music sub1
                    [image] => 
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [EventDate] => Array
                (
                )

            [EventMedia] => Array
                (
                )

            [EventTicket] => Array
                (
                )

        )

)
$filteredArray = Hash::extract($array, '{n}.Event[name=Troubadour]');
我们要索引此数组,并要搜索具有事件名称、组织名称、事件城市等的事件

我们做什么

我们在Solr方面非常新,目前正在使用SolrHPClient来实现这一点,但基于此阵列,这变得非常困难

感谢所有的帮助

更新


我们有一个cakephp应用程序,因为有搜索引擎。所以我们想集成ApacheSolr用于搜索

这是我们遵循的教程:

http://www.webdesignermag.co.uk/tutorials/how-to-add-search-with-solr/
但是对于纯php,我们需要将其集成到cakephp中

我们怎样才能做到这一点

根据以上教程,在搜索之前,需要首先索引所有数据和记录

因此,上面的数组是我们现在的所有数据

当我们输入搜索文本为
Troubadour
和城市为
Indianapolis
时,搜索条件如下:

( Event.name = Troubadour OR Event.location = Troubadour OR Organization.name = Troubadour) AND Event.city = Indianapolis
这是我们的设想


Anyboady帮帮我吧……这是在浪费我的3天时间,但仍然……

假设您无法直接过滤数据库中的数据,并且必须过滤生成的数组(但请解释一下为什么不能),cakephp允许您从数组中提取过滤后的数据,如下所示:

Array
(
    [0] => Array
        (
            [Event] => Array
                (
                    [id] => 1
                    [org_id] => 1
                    [name] => Troubadour
                    [url_seo] => think-alone
                    [description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
                    [category_id] => 1
                    [sub_category_id] => 1
                    [special_offer] => yes
                    [capacity] => 100
                    [visibility] => E
                    [location] => Old National Centre     502 North New Jersey St Indianapolis, IN, 46204
                    [address] => Old National Centre      502 North New Jersey St Indianapolis, IN, 46204
                    [city] => Indianapolis
                    [state] => WA
                    [country] => US
                    [zipcode] => 98828 
                    [fb_url] => https://www.facebook.com/Think Alone
                    [twitter_url] => https://www.twitter.com/Think Alone
                    [status] => A
                    [featured] => Y
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Organization] => Array
                (
                    [id] => 1
                    [user_id] => 2
                    [name] =>  test org
                    [company_profile] => We are a company built on integrity
                    [motto] => Engineering Knowledge
                    [logo] => 
                    [website] => http://www. test org.com/
                    [subdomain] => 
                    [timezone] => 
                    [currency] => 
                    [video_link] => 
                    [company_email] => info@ test org.com
                    [contact_address] =>  test org Technologies. 4th and 5th floor,  Asset Iris Building, N F Gate Main Road, Tripunithura, Cochin,  India    - 682 301
                    [contact_phone] => + 91 484 2785 833
                    [contact_mobile] => 
                    [city] => Cochin
                    [state] => Ernakulam
                    [country] => india
                    [zipcode] => 682 301
                    [email_notification] => 1
                    [fb_url] => https://www.facebook.com/ test org
                    [twitter_url] => https://www.twitter.com/ test org
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Category] => Array
                (
                    [id] => 1
                    [name] => Business
                    [image] => 
                    [category_code] => business
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [SubCategory] => Array
                (
                    [id] => 1
                    [category_id] => 1
                    [name] => Advertising & Marketing 
                    [image] => 
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [EventDate] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [start_date] => 2013-09-21
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-22
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 9
                            [event_id] => 1
                            [start_date] => 2013-09-23
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-24
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-19 00:00:00
                            [modified] => 2013-09-19 00:00:00
                        )

                    [2] => Array
                        (
                            [id] => 7
                            [event_id] => 1
                            [start_date] => 2013-09-27
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-28
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-18 00:00:00
                            [modified] => 2013-09-18 00:00:00
                        )

                    [3] => Array
                        (
                            [id] => 14
                            [event_id] => 1
                            [start_date] => 2013-09-29
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-09-30
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-25 00:00:00
                            [modified] => 2013-09-25 00:00:00
                        )

                    [4] => Array
                        (
                            [id] => 6
                            [event_id] => 1
                            [start_date] => 2013-10-15
                            [start_time] => 10:00:00
                            [start_session] => A
                            [end_date] => 2013-10-15
                            [end_time] => 5:00:00
                            [end_session] => P
                            [created] => 2013-09-18 00:00:00
                            [modified] => 2013-09-18 00:00:00
                        )

                )

            [EventMedia] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [image_url] => upcom-img1.jpg
                            [video_url] => 
                            [created] => 2013-09-25 00:00:00
                            [modified] => 2013-09-25 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 6
                            [event_id] => 1
                            [image_url] => upcom-img4.jpg
                            [video_url] => 
                            [created] => 0000-00-00 00:00:00
                            [modified] => 0000-00-00 00:00:00
                        )

                )

            [EventTicket] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [event_id] => 1
                            [name] => VIP Early Bird Experience
                            [inventory] => 60
                            [pricing] => P
                            [price] => 30
                            [more_info] => It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable Eng
                            [sale_start_date] => 2013-09-15
                            [sale_start_time] => 10.00 AM
                            [sale_end_date] => 2013-09-20
                            [sale_end_time] => 5.00 PM
                            [min_tickets_per_order] => 1
                            [max_tickets_per_order] => 1
                            [ticket_series] => 1_1000
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [event_id] => 1
                            [name] => Craft Beer Heaven
                            [inventory] => 40
                            [pricing] => P
                            [price] => 20
                            [more_info] => It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable Eng
                            [sale_start_date] => 2013-09-16
                            [sale_start_time] => 10.00 AM
                            [sale_end_date] => 2013-09-20
                            [sale_end_time] => 5.00 PM
                            [min_tickets_per_order] => 1
                            [max_tickets_per_order] => 1
                            [ticket_series] => 1_1061
                            [created] => 2013-09-13 00:00:00
                            [modified] => 2013-09-13 00:00:00
                        )

                )

        )

    [1] => Array
        (
            [Event] => Array
                (
                    [id] => 10
                    [org_id] => 1
                    [name] => Music Night
                    [url_seo] => music-night
                    [description] => Contrary to popular belief, Lorem Ipsum is not simply random text. 
                    [category_id] => 2
                    [sub_category_id] => 3
                    [special_offer] => no
                    [capacity] => 30
                    [visibility] => E
                    [location] => Los Angeles
                    [address] => The Echo     1822 W Sunset Blvd Los Angeles, California, 90026
                    [city] => Los Angeles
                    [state] => California
                    [country] => US
                    [zipcode] => 90026
                    [fb_url] => http://www.facebook.com/music-night
                    [twitter_url] => http://www.twitter.com/music-night
                    [status] => A
                    [featured] => N
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Organization] => Array
                (
                    [id] => 1
                    [user_id] => 2
                    [name] =>  test org
                    [company_profile] => We are a company built on integrity
                    [motto] => Engineering Knowledge
                    [logo] => 
                    [website] => http://www. test org.com/
                    [subdomain] => 
                    [timezone] => 
                    [currency] => 
                    [video_link] => 
                    [company_email] => info@ test org.com
                    [contact_address] =>  test org Technologies. 4th and 5th floor,  Asset Iris Building, N F Gate Main Road, Tripunithura, Cochin,  India    - 682 301
                    [contact_phone] => + 91 484 2785 833
                    [contact_mobile] => 
                    [city] => Cochin
                    [state] => Ernakulam
                    [country] => india
                    [zipcode] => 682 301
                    [email_notification] => 1
                    [fb_url] => https://www.facebook.com/ test org
                    [twitter_url] => https://www.twitter.com/ test org
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [Category] => Array
                (
                    [id] => 2
                    [name] => Music & nightlife
                    [image] => 
                    [category_code] => music
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [SubCategory] => Array
                (
                    [id] => 3
                    [category_id] => 2
                    [name] => music sub1
                    [image] => 
                    [status] => 1
                    [created] => 2013-09-13 00:00:00
                    [modified] => 2013-09-13 00:00:00
                )

            [EventDate] => Array
                (
                )

            [EventMedia] => Array
                (
                )

            [EventTicket] => Array
                (
                )

        )

)
$filteredArray = Hash::extract($array, '{n}.Event[name=Troubadour]');


希望这能回答你的问题

请清楚地解释你想要在这个阵列中得到什么?@NathanSrivi,请查看我的更新。。。。。。