2012-09-04 94 views
5

如果我有關鍵字Chris Muench的記錄,我希望能夠匹配Mue或Chr。我如何用solr查詢來做到這一點。目前,我做到以下幾點:Solr通配符搜索

$results = $solr->search('"'.Apache_Solr_Service::escape($_GET['textsearch']).'"~100', 0, 100, array('fq' => 'type:datacollection')); 

不匹配MUE或人權委員會,但它確實符合Muench的

模式:

<?xml version="1.0" encoding="UTF-8" ?> 
<schema name="rocdocs" version="1.4"> 
    <types> 
    <!-- The StrField type is not analyzed, but indexed/stored verbatim. --> 
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/> 
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> 
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> 
     <analyzer type="index"> 
     <tokenizer class="solr.StandardTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
     <!-- in this example, we will only use synonyms at query time 
     <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> 
     --> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     </analyzer> 
     <analyzer type="query"> 
     <tokenizer class="solr.StandardTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
     <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     </analyzer> 
    </fieldType> 
</types> 


<fields> 
    <field name="type" type="string" indexed="true" stored="true" required="true" /> 
    <field name="mongo_id" type="string" indexed="true" stored="true" required="true" /> 
    <field name="nid" type="int" indexed="true" stored="true" required="true" /> 
    <field name="keywords" type="text_general" indexed="true" stored="false" /> 
</fields> 

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

<!-- field for the QueryParser to use when an explicit fieldname is absent --> 
<defaultSearchField>keywords</defaultSearchField> 
<!-- SolrQueryParser configuration: defaultOperator="AND|OR" --> 
<solrQueryParser defaultOperator="OR"/> 
</schema> 
+0

相關SO問題,與其他技巧,在這裏:http://stackoverflow.com/questions/1974394/apache-solr-search-part-of-the-word/1976045#1976045 –

回答

7

您必須要麼使用wildcard queries例如chr *或mue *這將匹配。
這將使客戶端以此格式輸入查詢或在應用程序中修改它。
否則,您可以使用solr.EdgeNGramFilterFactory生成令牌,這將匹配記錄。例如chris會產生ch,chr,chri,chris,因此會匹配所有這些組合。

+0

我試着做:$結果= $ solr-> search('''。Apache_Solr_Service :: escape($ _ GET ['textsearch'])。'*「〜100',0,100,array('fq'=>'type:datacollection'));它仍然不匹配。我寧願在搜索查詢中執行此操作,而不使用NGramFilterFactory, –

+1

通配符查詢的問題在於它們在查詢期間不經歷分析,因此可能不匹配。嘗試搜索小寫,因爲您在索引時間分析中使用小寫。 – Jayendra

+0

這似乎也沒有幫助。我需要在我的模式中做些什麼嗎? –