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条)

报告相同问题?