最新消息: 新版網站上線了?。?!
  • php使用solr對關鍵詞多字段查詢和全文檢索

    一、說明

    1、solr版本是7.7.0

    2、系統環境windows

    3、solr啟動 直接進入solr文件夾下的bin目錄,執行solr start

    D:\solr-7.7.0\bin>solr start

    4、由于這篇文章說的是php調用solr擴展時,一個關鍵詞如何在多個字段查詢搜索,所以就省略了solr的安裝和solr core的生成,對于安裝過程和配置如有疑問請加   QQ:1914421469

    一、solr的安裝省略

    二、生成core省略

    三、我這里已經生成了一個core名稱為bug

    在solr中配置bug對應數據源,我的數據源配置文件為db-data-config.xml

    db-data-config.xml :

    <dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/testlink_quality" user="root" password="123456" />
    <document>
    <entity name="mantis_bug" query="select * from mantis_bug" pk="id">
    <field column='id' name='id' />
    <field column='summary' name='summary' />
    <field column='project_id' name='project_id' />
    <field column='description' name='description' />
    </entity>
    </document>
    </dataConfig>

    四、在php代碼中調用solr進行搜索查詢

    $options = array(
        'hostname' => 'localhost',
        'path'     => 'solr/bug',
        'port'     => '8983'
    );
    $solrClient = new SolrClient($options);
    $keyword = $_REQUEST['keyword'];    //搜索關鍵詞,以“庫存”為例
    $query = new SolrQuery();
    //$query->setQuery('summary:庫存 or description:庫存'); 在summary和description2個字段中搜索‘庫存’關鍵詞
    $query->setQuery('summary:'.$keyword.' or description:'.$keyword); //看到了把在多個字段中查詢同一個關鍵詞時,可以使用or進行拼接
    $query->setStart(0);
    $query->setRows(50);
    $query->addField('summary');
    $query->addField('description');
    $query->addField('project_id');
    $query->addField('id');
    $query_response = $solrClient->query($query);
    $response = $query_response->getResponse();
    echo "<pre>";
    print_r($response);


    五、結果

    SolrObject Object
    (
        [responseHeader] => SolrObject Object
            (
                [status] => 0
                [QTime] => 1
                [params] => SolrObject Object
                    (
                        [q] => summary:庫存 or description:庫存
                        [indent] => on
                        [fl] => summary,description,project_id,id
                        [start] => 0
                        [rows] => 50
                        [version] => 2.2
                        [wt] => xml
                    )
    
            )
    
        [response] => SolrObject Object
            (
                [numFound] => 13
                [start] => 0
                [docs] => Array
                    (
                        [0] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 憑證庫存查詢查詢結果為空
                                    )
    
                                [description] => 憑證庫存查詢交易查詢不到數據
                                [project_id] => 1375
                                [id] => 7
                            )
    
                        [1] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 查詢庫存憑證報錯
                                    )
    
                                [description] => 1.進入“查詢庫存憑證”交易
    2.點擊【查詢】按鈕,報錯,如圖:01.png
                                [project_id] => 1427
                                [id] => 512
                            )
    
                        [2] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 查詢庫存憑證-查詢條件憑證種類無效
                                    )
    
                                [description] => 1.進入“查詢庫存憑證”,憑證種類選擇“116-現金支票”,點擊查詢
    2.查詢結果未篩選出現金支票的結果,如圖:01.png
                                [project_id] => 1427
                                [id] => 607
                            )
    
                        [3] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20350重要物品出入庫:物品入庫成功后,庫存余額一直是0
                                    )
    
                                [description] => 重要物品入庫:提交交易后,返回信息處庫存余額顯示為0
                                [project_id] => 1427
                                [id] => 1200
                            )
    
                        [4] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20350重要物品出入庫:庫存為0時,進行出庫交易時,系統應該給出相應提示,而不是出庫成功
                                    )
    
                                [description] => 前提:金銀首飾的庫存為0
    1.選擇操作標志出庫
    2.點擊添加,選擇重要物品種類:金銀首飾 ,輸入數量4,點擊提交
    3.點擊提交,系統應該給出相應提示“庫存為0”
                                [project_id] => 1427
                                [id] => 1553
                            )
    
                        [5] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20163查詢庫存憑證-憑證種類顯示名稱與其他地方不一樣
                                    )
    
                                [description] => 1.柜員號:069501,進入查詢庫存憑證交易
    2.憑證種類選擇 184-IC卡,其他模塊該種憑證叫,184-金農IC卡。如圖:01.png
    需要修改為一致
                                [project_id] => 1427
                                [id] => 1279
                            )
    
                        [6] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20102現金出入庫,資金去向為存放人行時的現金出庫自動回顯的賬號為庫存現金內部賬
                                    )
    
                                [description] => 20102現金出入庫,資金去向為存放人行時的現金出庫自動回顯的賬號為庫存現金內部賬
                                [project_id] => 1427
                                [id] => 2265
                            )
    
                        [7] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20350重要物品出入庫:當輸入的物品數量大于實際庫存數量時,系統應該給出錯誤提示
                                    )
    
                                [description] => 金銀首飾實際庫存5
    1.選擇操作標志出庫
    2.點擊添加,選擇重要物品種類金銀首飾,輸入數量6,點擊提交
    3.點擊提交,提交成功
                                [project_id] => 1427
                                [id] => 1564
                            )
    
                        [8] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 憑證入庫沖回
                                    )
    
                                [description] => 憑證入庫沖回后查詢庫存憑證狀態依然正常,未將庫存憑證狀態更改
                                [project_id] => 1375
                                [id] => 443
                            )
    
                        [9] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 查詢打印表外憑證銷號清單
                                    )
    
                                [description] => 1、測試結果為庫存憑證,而不是銷號使用的憑證;2、管理柜員不能查詢普通柜員銷號憑證;3、管理柜員不能查詢本機構的銷號憑證。
                                [project_id] => 1375
                                [id] => 68
                            )
    
                        [10] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 查詢庫存現金交易測試報查找柜員尾箱定義表出錯
                                    )
    
                                [description] => FDB0001:查找柜員尾箱定義表出錯,100+3401010003
                                [project_id] => 1375
                                [id] => 1
                            )
    
                        [11] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 證明書補打,提交后報憑證號已使用,但憑證狀態時正常
                                    )
    
                                [description] => 證明書補打,當存款證明編號為DPZM0000000025,憑證起號為1000100060000022提交報錯,提示1000100060000022已被使用,查詢庫存憑證1000100060000022憑證狀態正常
                                [project_id] => 1427
                                [id] => 2045
                            )
    
                        [12] => SolrObject Object
                            (
                                [summary] => Array
                                    (
                                        [0] => 20054/機構查庫登記查詢,機構查庫查詢結果打印錯誤
                                    )
    
                                [description] => 20054/機構查庫登記查詢,機構查庫登記查詢結果打印錯誤(查看詳情,打印預覽界面,“幣種”“檢查結果”列表中缺少字符)and(庫存現金檢查界面,”幣種“列表下也缺少字符)
                                [project_id] => 1427
                                [id] => 2707
                            )
    
                    )
    
            )
    
    )


    轉載請注明:谷谷點程序 » php使用solr對關鍵詞多字段查詢和全文檢索

    平度胜利路按摩在什么地方多,平度做大活的足疗,平度职教中心女孩微信,平度找曼地方