2017-02-26 151 views
0

我試圖搜索HTML文件的集合,並在Solr 6.4.1中提供摘錄。而且由於突出顯示需要返回乾淨的可讀文本,所以需要將HTML分解爲裸文本並存儲。在Solr中剝離,存儲和索引HTML文件

但無論我在覈心配置中做了什麼改變,我指定的字段都不會返回到結果中,並且文檔的高亮顯示始終爲空{}。

託管模式:

<fieldType name="text_en_splitting_html" class="solr.TextField" autoGeneratePhraseQueries="true" positionIncrementGap="100"> 
    <analyzer type="index"> 
     <charFilter class="solr.HTMLStripCharFilterFactory"/> 
     <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/> 
     <filter class="solr.WordDelimiterFilterFactory" catenateNumbers="1" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="1"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/> 
     <filter class="solr.PorterStemFilterFactory"/> 
    </analyzer> 
    <analyzer type="query"> 
     <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
     <filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/> 
     <filter class="solr.StopFilterFactory" words="lang/stopwords_en.txt" ignoreCase="true"/> 
     <filter class="solr.WordDelimiterFilterFactory" catenateNumbers="0" generateNumberParts="1" splitOnCaseChange="1" generateWordParts="1" catenateAll="0" catenateWords="0"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/> 
     <filter class="solr.PorterStemFilterFactory"/> 
    </analyzer> 
    </fieldType> 

    <field name="content1" type="text_en_splitting_html" multiValued="true" indexed="true" stored="true"/> 

solrconfig.xml中是默認的,默認/更新/提取requestHandler。我得到的迴應是:

{ 
    "responseHeader":{ 
    "status":0, 
    "QTime":4, 
    "params":{ 
     "q":"*:*", 
     "hl":"on", 
     "indent":"on", 
     "hl.fl":"content1", 
     "wt":"json", 
     "_":"1488077854581"}}, 
    "response":{"numFound":100,"start":0,"docs":[ 
     { 
     "id":"/home/me/files/d1/test.html", 
     "stream_size":[62963], 
     "x_parsed_by":["org.apache.tika.parser.DefaultParser", 
      "org.apache.tika.parser.html.HtmlParser"], 
     "creator":["createhtml"], 
     "stream_content_type":["text/html"], 
     "viewport":["width=device-width, initial-scale=1"], 
     "dc_title":["A nice read"], 
     "content_encoding":["UTF-8"], 
     "resourcename":["/home/me/files/d1/test.html"], 
     "title":["A nice read"], 
     "creator_url":["http://createhtml.net"], 
     "content_type":["text/html; charset=UTF-8"], 
     "_version_":1560362957551960064} 
... 
}, 
    "highlighting":{ 
    "/home/me/files/d1/test.html":{}, 
... 

我與

/opt/solr/bin/post -c mycollection -filetypes html files/ 

我也試圖與提卡提取物處理

<requestHandler name="/update/extract" class="org.apache.solr.handler.extraction.ExtractingRequestHandler"> 
    <lst name="defaults"> 
     <str name="fmap.Last-Modified">last_modified</str> 
    </lst> 
</requestHandler> 

,但成效有限索引。 「內容」字段現在出現在響應中,它包含的內容似乎是初始文檔的糟糕和不完整的版本。突出顯示似乎工作,但它不乾淨。

所以我需要的Solr做的是:

  • 清理完全是我的HTML(無標籤,類名或內嵌樣式 - 就像JavaScript的的.text()方法)
  • 執行搜索在剝離內容
  • 回報剝離的內容,如果我要求它
  • 回報剝離內容高亮

看來,不管我改變了什麼(除了Tika以上),「content1」被忽略。

所有我在這裏試圖做的,簡單地說,就是能夠搜索HTML文件並提供像任何其他搜索引擎的摘錄。

+0

您能否在Solr服務器前端確定content1字段中是否存在實際內容?如果是的話,你可以在你的查詢中使用帶有content1字段的'fl'參數嗎?這會改變結果嗎? –

回答

0

我無法完成這項工作,Tika也無法正確刪除HTML,所以我通過使用Solr和PHPQuery的Solarium PHP客戶端來解析,剝離,提取數據,然後形成我自己的文檔以直接發佈到Solr。

問題是在執行使用Tika的solrconfig.xml中定義的ERH(ExtractRequestHandler)。通過使用Solarium,ERH被繞過,所以我在managed-schema中定義的所有字段都開始被/ update請求處理程序使用。