1. 程式人生 > >Solr學習總結-查詢

Solr學習總結-查詢

指定field查詢

http://localhost:8983/solr/select?q=author:rafal

按照dismax查詢:可以指定多個域,每個域的匹配都有不同的分數

http://localhost:8080/solr/select?q=title&qf=title^1 text^5&defType=dismax

按照“或”的關係查詢

http://localhost:8983/solr/select?q=author:(solr cookbook)

按照某個field排序

http://localhost:8983/solr/select?q=solr&sort=author+asc,score+desc


選擇不同的query parser,可以定製針對不同的單詞采用不同的查詢方法

http://localhost:8983/solr/select?q=book&qf=title&defType=dismax

執行phrase查詢以及slope

http://localhost:8983/solr/select?q=title:"2010 report"~1

針對phrase查詢,如果滿足單詞相鄰,boost他

http://localhost:8983/solr/select? defType=dismax&pf=title^100&q=2010+report&qf=title


http://localhost:8983/solr/select?q=title:(2010+AND+report)+OR+title:"2010+report"^100

針對具體的查詢串(一般是string),給予排名自定義(前提是得分相同)。首先在sorlconfig.xml中定義下面

  1. <searchComponent name="elevator" class="solr.QueryElevationComponent"  
  2. >  
  3. <str name="queryFieldType">string</str>  
  4. <str name="config-file">elevate.xml</str>  
  5. </searchComponent>  
  6. <requestHandler name="/promotion" class="solr.SearchHandler">  
  7. <arr name="last-components">  
  8. <str>elevator</str>  
  9. </arr>  
  10. </requestHandler>  
其次編寫elevate.xml:
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <elevate>  
  3. <query text="solr">  
  4. <doc id="3" />  
  5. <doc id="1" exclude="true" /><!-- 此檔案不會被查詢到,相當於被百度遮蔽 -->  
  6. </query>  
  7. </elevate>  
最後查詢:http://localhost:8983/solr/promotion?q=solr

按照距離查詢

http://localhost:8983/solr/select?q=company&sort=dist(2,x,y,0,0)+asc

指定滿足查詢詞的數量:其中mm即為妖滿足的查詢詞的數量

http://localhost:8983/solr/select?q=book+revised+another+ different+word+that+doesnt+count&defType=dismax&mm=2

按照指定的field排名,下面是按照sold排名評分:

http://localhost:8983/solr/select?defType=dismax&qf=title&q=revised&fl=*,score&bf=product(sold)

嵌入查詢,滿足花括號內的條件的將分數相乘

http://localhost:8983/solr/select?q=revised+AND+book+AND+_query_:"{!dismax qf=title pf=title^10 v=$qq}"&qq=revised+book