douwei1921 2009-12-19 14:26
浏览 62
已采纳

我该怎么做,自己创建一个搜索引擎或使用另一个?

I have this classifieds website and I have now been searching for ways to implement a search function of the classifieds.

I wonder, is there any tutorial for creating a pretty powerful search engine in PHP that you know of?

I have looked into third party search engines, and it feels they are too much...

PS: No full-text support on my server.

Thanks

  • 写回答

6条回答 默认 最新

  • dsxrq28228 2009-12-19 14:37
    关注

    To be honest, I would recommend using Zend_Lucene, as although it looks confusing at first, it is very simple to use once you get to grips with it. Although indexing is slow, searching is very fast.

    If you want to write a fast and powerful search engine, you are not going to find an implementation in a tutorial, you would be best of doing some research and reading so papers on the subject. In other words, you are not going to be able to write anything in PHP to rival Zend Lucene without a lot of research and hard work.

    The documents are very very good, and I have managed to implement Zend Lucene in a none zend framework based project. It just requires half an hour spent reading and digesting the documents and another half hour writing a quick set of tests to check your assumptions are correct.

    To create a document with a car id and make:

    //if it hasn't been created, you need to use ::create rather than ::open
    $index = Zend_Search_Lucene::open('/data/my-index');
    
    $doc = new Zend_Search_Lucene_Document();
    $doc->addField(Zend_Search_Lucene_Field::Text('Car', 'MyCar'));
    $doc->addField(Zend_Search_Lucene_Field::Text('Make', 'BMW'));
    
    $index->addDocument($doc);
    

    The to find the cars:

    $index = Zend_Search_Lucene::open('/data/my-index');
    $result = $index->find('Car:MyCar');
    
    foreach ( $result as $hit ){
        echo $hit->Make;
    }
    

    The downside is that Zend_Lucene isn't a storage engine, it doesn't make any guarantees about the storage, so although you can use it to store records, using a proper database would be a better option. This is one of the issues that I encountered, you just have to keep both the search index and the database synchronized. The best way I found was just to create a wrapper class that called add/remove on both the database and the index.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站