2012-09-11 47 views
1

我索引了使用solr進行查詢的存檔網站的集合。作爲唯一的密鑰,我使用網站的網址。我想要做的是在過濾器查詢中使用url字段,以便在需要時將搜索限制到某個域。例如,我想查詢「Barack Obama」,但將結果限制在「whitehouse.gov」域。聽起來像是一個非常基本的用例,但是在URL字段中的搜索根本不會返回任何結果。這裏是我的配置(schema.xml中):索引和查詢唯一密鑰URL Solr

. 
. 
. 
<field name="collection" type="string" indexed="true" stored="true"/> 
<field name="content" type="text_de" indexed="true" stored="true" multiValued="true"/> 
<field name="date" type="string" indexed="true" stored="true"/> 
<field name="digest" type="string" indexed="true" stored="true"/> 
<field name="length" type="string" indexed="true" stored="true"/> 
<field name="segment" type="string" indexed="true" stored="true"/> 
<field name="site" type="string" indexed="true" stored="true"/> 
<field name="title" type="text_de" indexed="true" stored="true" multiValued="true"/> 
<field name="type" type="string" indexed="true" stored="true"/> 
<field name="url" type="text_en_splitting" indexed="true" stored="true"/> 
. 
. 
. 

<!-- Field to use to determine and enforce document uniqueness. 
    Unless this field is marked with required="false", it will be a required field 
--> 
<uniqueKey>url</uniqueKey> 

這裏是我的查詢(簡體):

http://mysolrserver.com:8983/solr/select/?q=content:Barack+Obama&fq=url:whitehouse.gov 

查詢分析器告訴我,說我的查詢應符合:

screenshot solr analysis

有沒有人有一個想法,爲什麼這是行不通的?我高度讚賞我可以得到的任何提示!非常感謝你們!

回答

2

fq=url:whitehouse.gov過濾應該工作。

但是,我發現問題與查詢q=content:Barack+Obama
什麼是您的默認搜索字段?
是否刪除查詢組件並使用q=*:*爲您返回結果。 ??

q=content:Barack+Obama查詢實際上將導致到像content:barack defaultsearchfield:obama
作爲默認搜索字段查詢不會有奧巴馬這不會導致任何結果。

+0

謝謝,這解決了我的問題的一部分!!但是,URL字段上的查詢行爲與我在分析器上看到的不匹配(請參閱附加圖像)。我只在使用通配符搜索時纔得到結果:fq = url:* whitehouse.gov *。雖然這樣對我來說很好,但它工作得很好。我現在試圖找出如何限制搜索結果到多個網址:q = Barack + Obama + url:(* whitehouse.gov *%20OR%20 * foxnews.com *)。我從中得到的結果與q = Barack + Obama不同,但結果不僅包含期望的子集,還包含多個其他網站的結果... – user871784

+0

您可以嘗試fq = url:(whitehouse.gov或foxnews .com) – Jayendra

+0

謝謝你,就是這樣! – user871784