Solr自學筆記 2 —— Solr 查詢,排序, 高亮


 

1.查詢(Querying Data) --q 文檔 fl 表示相應的屬性
     1) 內容: 搜索過程是通過帶q參數的GET HTTP請求select URL.同時可以通過傳遞表示可選擇的請求參數的數字給請求處理器來控制相應的返回信息。(You can pass a number of optional request parameters to the request handler to control what information is returned
     下面f1參數來控制相應的返回的屬性值:
     Solr Query Syntax (q參數的規則)地址: http://wiki.apache.org/solr/SolrQuerySyntax
    
     查詢例子1:
     GET請求:http://localhost:8983/solr/collection1/select?q=*:*&fl=name,id&wt=json&fl=* 
     分析:q=*:* 表示 屬性:屬性值中包含的詞
          fl=*  表示 查詢的結果返回所有的屬性值
     返回的內容:
          {
    "responseHeader": {
        "status": 0,
        "QTime": 1,
        "params": {
            "fl": [
                "name,id",
                "*"
            ],
            "q": "*:*",
            "wt": "json"
        }
    },
    "response": {
        "numFound": 2,
        "start": 0,
        "docs": [
            {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "manu": "Apache Software Foundation",
                "cat": [
                    "software",
                    "search"
                ],
                "features": [
                    "Advanced Full-Text Search Capabilities using Lucene",
                    "Optimized for High Volume Web Traffic",
                    "Standards Based Open Interfaces - XML and HTTP",
                    "Comprehensive HTML Administration Interfaces",
                    "Scalability - Efficient Replication to other Solr Search Servers",
                    "Flexible and Adaptable with XML configuration and Schema",
                    "Good unicode support: héllo (hello with an accent over the e)"
                ],
                "price": 0,
                "price_c": "0,USD",
                "popularity": 10,
                "inStock": true,
                "incubationdate_dt": "2006-01-17T00:00:00Z",
                "_version_": 1546511824707387400
            },
            {
                "id": "3007WFP",
                "name": "Dell Widescreen UltraSharp 3007WFP",
                "manu": "Dell, Inc.",
                "manu_id_s": "dell",
                "cat": [
                    "electronics and computer1"
                ],
                "features": [
                    "30\" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"
                ],
                "includes": "USB cable",
                "weight": 401.6,
                "price": 2199,
                "price_c": "2199,USD",
                "popularity": 6,
                "inStock": true,
                "store": "43.17614,-90.57341",
                "_version_": 1546511824826925000
            }
        ]
    }
}
 查詢例子2:
     GET請求:http://localhost:8983/solr/collection1/select?q=Search&fl=name,id
&wt=json&fl=* 
     分析:q=Search 表示 所有屬性值中必包含的這個詞,不一定所有屬性都包含,也可以為*。
          fl=*  表示 查詢的結果返回所有的屬性值
     返回的內容:
          {
    "responseHeader": {
        "status": 0,
        "QTime": 36,
        "params": {
            "fl": [
                "name,id",
                "*"
            ],
            "q": "Search",
            "wt": "json"
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
            {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "manu": "Apache Software Foundation",
                "cat": [
                    "software",
                    "search"
                ],
                "features": [
                    "Advanced Full-Text Search Capabilities using Lucene",
                    "Optimized for High Volume Web Traffic",
                    "Standards Based Open Interfaces - XML and HTTP",
                    "Comprehensive HTML Administration Interfaces",
                    "Scalability - Efficient Replication to other Solr Search Servers",
                    "Flexible and Adaptable with XML configuration and Schema",
                    "Good unicode support: h¨¦llo (hello with an accent over the e)"
                ],
                "price": 0,
                "price_c": "0,USD",
                "popularity": 10,
                "inStock": true,
                "incubationdate_dt": "2006-01-17T00:00:00Z",
                "_version_": 1546511824707387400
            }
        ]
    }
}
 
 2. 排序(Sorting)--sort 屬性
3.高亮 (Highlighting)
Hit highlighting returns relevant snippets of each returned document, and highlights terms from the query within those context snippets.
 
     返回的形式:這會導致高亮的部分會顯示在返回值上相關的高亮的詞語上包含在<em></em>(for emphasis) tags
     get請求URL:   http://localhost:8983/solr/collection1/select?q=Search&fl=name,id &wt=json
&hl=true&hl.fl=features   
     返回值:     
{
    "responseHeader": {
        "status": 0,
        "QTime": 46,
        "params": { //請求參數
            "fl": "name,id", //請求返回的屬性值
            "q": "Search",    //關鍵詞搜索
            "hl.fl": "features", //高亮所包含的關鍵詞
            "wt": "json",     //返回的形式
            "hl": "true"      // 是否高亮
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
            {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server"
            }
        ]
    },
    "highlighting": {
        "SOLR1000": {
            "features": [
                "Advanced Full-Text <em>Search</em> Capabilities using Lucene"
            ]
        }
    }
}
 
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM