2016-12-01 42 views
0

我是一名Solr初學者,從第一次開始,我就用它爲我的項目工作了一個月,一切都很好,但我遇到了問題。如果我有這樣一句話:「當你愛一個人時,世界正在閃耀」。如果我用'當你'或'閃亮'沒有結果,但當我嘗試使用'你愛'或'世界是',或者只是'愛'或某種類型時,結果就會出現。我想問一下如何通過schemal.xml文件進行配置,或者我犯了什麼錯誤,謝謝!爲什麼我不能搜索Solr字段中的第一個單詞或最後一個單詞?

這裏是Schema.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<schema name="minimal" version="1.1"> 
    <field name="_version_" type="long" indexed="true" stored="false" /> 
    <field name="_root_" type="string" indexed="true" stored="false" docValues="false" /> 

    <uniqueKey>id</uniqueKey> 
    <solrQueryParser defaultOperator="AND"/> 

    <field name="dplname" type="text_general" multiValued="false" indexed="true" required="true" stored="true"/> 
    <field name="mail" type="text_general" indexed="true" stored="true" multiValued="true"/> 
    <field name="phone" type="text_general" indexed="true" stored="true"/> 

    <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/> 
    <field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/> 

    <copyField source="dplname" dest="text"/> 
    <copyField source="mail" dest="text"/> 
    <copyField source="phone" dest="text"/> 

    <fieldType name="int" class="solr.TrieIntField" docValues="true" precisionStep="0" positionIncrementGap="0"/> 
    <fieldType name="float" class="solr.TrieFloatField" docValues="true" precisionStep="0" positionIncrementGap="0"/> 
    <fieldType name="long" class="solr.TrieLongField" docValues="true" precisionStep="0" positionIncrementGap="0"/> 
    <fieldType name="double" class="solr.TrieDoubleField" docValues="true" precisionStep="0" positionIncrementGap="0"/> 

    <fieldType name="string" class="solr.StrField" sortMissingLast="true" /> 
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/> 

    <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" /> 
     <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 
    <analyzer type="query"> 
     <tokenizer class="solr.StandardTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> 
     <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 
    </fieldType> 
</schema> 

更新:我用這個查詢來搜索:dplname:明媚或種類。

+0

你是如何搜索?至於你的查詢是什麼? – root545

+0

嗨,我的查詢是dplname:*明媚*或種類。 – iamatsundere181

+0

你有意做外卡搜索嗎?如果你只搜索這樣'dplname會發生什麼:shining' – root545

回答

1

好的。所以你需要了解如何在solr中分析和標記文本。 在你的情況,如果你在你的schema.xml

<analyzer type="index"> 
     <tokenizer class="solr.StandardTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> 
     <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 

看看這是什麼意思是,雖然索引文件StandardTokenizerFactory將應用打破基於空格和一些其他的分隔符的句子。

在這裏閱讀詳細內容https://cwiki.apache.org/confluence/display/solr/Tokenizers#Tokenizers-StandardTokenizer

例如,您的一句話:

當你愛一個人,這個世界燦爛

將被分爲下列標記

什麼時候,你,愛,某人,這個世界,是,閃耀

所以共有8個標記。注意,也將被刪除,因爲這也是一個分隔符。

然後StopFilterFactory過濾器適用於將刪除stopwords.txt文件中存在的停用詞。 (停止的話都是你不想要索引他們那種不尋找意義的常用詞。

這裏https://cwiki.apache.org/confluence/display/solr/Filter+Descriptions#FilterDescriptions-StopFilter閱讀)

讓我們假設停止詞是

你的,是

所以如果只剩下這些令牌(因爲停用詞被移除)第二過濾器後

時,愛一個人,世界,閃耀

現在第三濾波器是小寫的過濾器,它會轉換所有的標記爲小寫。

所以,當所有說的和做你的句子

當你愛一個人

總之,這個世界閃耀

轉位到followoing令牌

的時候,愛情,一個人,世界,閃耀

讓我們談談你的schema.xml中搜索又名查詢

你有以下

<analyzer type="query"> 
     <tokenizer class="solr.StandardTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> 
     <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 

這是什麼意思的是,上述分析儀會爲每個查詢來執行。

所以,當你搜索dplname:shining 的StandardTokenizerFactory對其進行解析,因爲沒有分隔符什麼也不會發生shining,因爲它也不是一個停用詞或者它不會被StopFilterFactory被刪除,LowerCaseFilterFactory僅改變它爲小寫。(如果它已經不是)

所以solr將搜索的最後一個令牌是shining,它在索引中找到並因此返回結果。

讓我們看看其他查詢

dplname:明媚

注:該字段只適用於它直接前面的名詞,所以在上面的查詢is中搜索dplname場,但因爲沒有什麼的shining它會在默認字段進行搜索前(在這種情況下,文本字段)。

所以基本上整個查詢就會變成(自defaultOperator是,它會在查詢中添加)

dplname:是和文字:閃亮

這樣的Solr正在搜索的文檔,其已在dplname領域isshining在文本字段。它不能找到。

在這裏閱讀的查詢解析:http://lucene.apache.org/core/2_9_4/queryparsersyntax.html

+0

這麼長時間,但你識破我,謝謝 – iamatsundere181

相關問題