使用 Solr 站內 搜尋 引擎

How to create search engine using Solr without painness

作者: 七味粉 |
文章2013-04-15
83 分享
28
    安裝及使用:
  • 下載及壓縮執行:

  • 
    
    [shell]wget http://download.nextag.com/apache/lucene/solr/4.2.0/solr-4.2.0.tgz
    [com]下載[/com]
    [shell]tar -zxvf solr-4.2.0.tgz
    [com]解壓縮執行[/com]

  • 啟動:

  • 
    
    [shell]cd solr/example
    [shell]java -jar start.jar [tell]執行主程式[/tell]


    INFO::Started [email protected]:8983 代表啟動

  • 搜尋資料:
    http://localhost:8983/solr/select?q=*:*&wt=xml

  • 索引範例:
    
    
    [shell]cd solr/example/exampledocs
    [shell]vim test.json
    [vim][tell]json格式[/tell]
    {
    "id" : "1",
    "name" : "第1篇文章"
    }
    ,
    {
    "id" : "2",
    "name" : "第2篇文章"
    }
    ][/vim]
    [shell]cd solr/example/exampledocs
    [shell]vim test.xml
    [vim][tell]XML格式[/tell]
    <add>
    <doc>
    <field name="id">1</field>
    <field name="name">第1篇文章內容</field>
    </doc>
    <doc>
    <field name="id">2</field>
    <field name="name">第2篇文章內容</field>
    </doc>[/vim]

  • 加入索引
    
    
    [shell]cd solr/example/exampledocs
    [shell]./post.sh test.xml


  • 修改 post.sh 成 json 格式
    
    
    [shell]cd solr/example/exampledocs
    [shell]cp post.sh post_json.sh
    [shell]vim post_json.sh
    [vim]curl $URL --data-binary @$f -H 'Content-type:application/json'
    [com] 第22行,xml 改成 json[/com][/vim]


  • 語法參數:
    q - 查詢字串,必須的。
    fq - 在q查詢符合結果中同時是fq查詢符合的。
    fl - 指定返回那些欄位內容,用逗號或空格分隔多個。
    start - 返回第一條記錄在完整找到結果中的偏移位置,0開始,一般分頁用。
    rows - 指定返回結果最多有多少條記錄,配合start來實現分頁。
    sort - 排序,格式:sort=+[,+]… 。示例:(inStock desc, price asc)表示先 “inStock” 降冪, 再 “price” 昇冪,默認是相關性降冪。
    wt - (writer type)指定輸出格式,可以有 xml, json, php, phps,
    q.op - 覆蓋 schema.xml 的 defaultOperator
    df - 默認的查詢欄位,一般默認指定
    qt - (query type)指定那個類型來處理查詢請求,一般不用指定,默認是standard。
    indent - true|on, json, php, phps, ruby輸出才有必要用這個參數。

貼心小提醒
1.您目前未登入,若於此狀態進行文章收藏,紀錄可能無法長期保留。
2.建議登入後進行收藏,好文會幫你保存著,隨時要看也不怕找不到唷~

KiKiNote持續為您提供最優質的資訊內容,謝謝您!
不再顯示此視窗

複製成功