好久沒有寫關于umbraco的博客了,這段時間在研究solis search,感覺它太強大,好東西是需要分享的,所以寫一篇簡單的使用博客分享給個人umbraco愛好者。
在了解solis search之前,我們需要簡單的了解apache solr,Apache Solr 是一個開源的搜索服務器。Solr 使用 java 語言開發,主要基于 HTTP 和 Apache Lucene 實現。Lucene是一套用于全文檢索和搜尋的開源程式庫,由Apache軟件基金會支持和提供。Lucene提供了一個簡單卻強大的應用程式接口,能夠做全文索引和搜尋。更詳細的介紹請充分利用搜索引擎,這里就不做詳細介紹了。
solis search就是基于apache solr開發的一個umbraco的插件。它在做了簡單的配置之后,就可以檢索到umbraco content里面的幾乎所有的文字內容,包括上傳的文檔或者選擇的media picker中的文檔(Word, pdf, Excel 等等)。
安裝java環境是為了運行apache solr server.
下載地址:http://www.java.com/zh_CN/,
下載后安裝,安裝之后請配置環境變量,是java命令可以直接在命令行根目錄運行。如何配置環境變量在這就不介紹了。
下載地址:http://lucene.apache.org/solr/,這里記住,一定要下載4.5.1版本的,不然使用會出現未知的錯誤。因為solis search是基于version 4.5開發的。
請參考官方文檔進行安裝:http://lucene.apache.org/solr/4_5_1/tutorial.html,
操作簡要說明:

下載:https://www.solissearch.com/download/
推薦下載Solis Search 1.1.15.218 Umbraco package, 下載之后再umbraco后臺進行安裝

安裝過程一般不會出錯,如果出了錯,請下載手動安裝包,根據文檔進行安裝:https://www.solissearch.com/documentation/
安裝之后,找到安裝包里面的schema.xml和solrconfig.xml然后 復制到solr的文件夾solr-4.5.1/example/solr/collection1/conf/下面,這一步很重要,然后重啟solr server:java -jar start.jar
接著就是rebuild index:

當然在rebuild index之前要根據具體的需要修改配置文件。
在這里,我將我的配置貼出來,并且做簡單的介紹,

1 <?xml version="1.0"?> 2 <SolisSearch> 3 <SolrServer address="http://localhost:8983/solr" username="" licenseKey="" /> 4 <SearchSettings defaultField="text" enableLanguageSupport="true" enabledLanguages="en" highlight="true" highlightFields="text" fragmenter="regex" fragsize="300" defaultOperator="AND" /> 5 <Languages> 6 <Language name="en" rootNode="1064" /> 7 </Languages> 8 <DocTypes> 9 <DocType name="default" addPageNameToContent="true">10 <PRoperties>11 <Property name="p1" property="Name" type="text" content="true" />12 <Property name="r1" property="relatedLinks" type="relatedLinks" parser="SolisSearch.Parsers.RelatedLinksParser,SolisSearch" />13 </Properties>14 </DocType>15 <DocType name="umbHomePage">16 <Properties>17 <Property name="p1" property="mainHeading" type="text" content="true" />18 <Property name="p2" property="mainContent" type="text" content="true" strView CodeSolrServer:配置solr server的 地址,用戶名以及license key.
SearchSettings: 配置當前search的環境,支持的語言,鏈接操作符,是否高亮等等
DocTypes:這個是重點,用來配置可以搜索出來的content字段
1 <DocType name="newsItem" addPageNameToContent="true">2 <Properties>3 <Property name="p1" property="title" type="text" content="true" />4 <Property name="p2" property="content" type="text" content="true" striphtml="true"/>5 <Property name="p3" property="downloadFile" type="relatedLinks" parser="SolisSearch.Parsers.RelatedLinksParser,SolisSearch" />6 <Property name="p4" property="uploadDoc" type="relatedLinks" parser="SolisSearch.Parsers.RelatedLinksParser,SolisSearch" />7 </Properties>8 </DocType>name="newsItem": 將名為newsItem的document type添加到可搜索列表;
addPageNameToContent="true": 表示該document type的name是可搜索的;
Properties: 指定該document type中哪些property是可以被搜索的;
Property: name - 標示符, property - 屬性名, type - 搜索的類型, content - 搜索的是內容值
type="relatedLinks": 表示使用solis search的方法去搜索,一般用來搜索word文檔,pdf文檔中的內容, 需要添加parser="SolisSearch.Parsers.RelatedLinksParser,SolisSearch".
這里的p3和p4表示添加了media picker類型以及upload的類型的屬性是可以搜索的。
搜索view代碼:
1 @using System.Activities.Statements 2 @using System.Globalization 3 @using SolisSearch.Helpers 4 @using SolisSearch.Repositories 5 @inherits Umbraco.Web.Macros.PartialViewMacroPage 6 7 @{ 8 Layout = "../Master.cshtml"; 9 } 10 11 12 <h1>@ViewBag.Title</h1> 13 <h3>@ViewData["content"]</h3> 14 15 @{ 16 var query = HttpUtility.UrlDecode(Request.QueryString["q"]); 17 var fq = new List<string>(); 18 19 20 <script type="text/Javascript"> 21 $(document).ready(function () { 22 23 $("#txtSearch").keydown(function (e) { 24 if (e.which == "13") { 25 $("#searchform").submit(); 26 } 27 }); 28 29 $(".facetlink").click(function () { 30 var filter = $(this).attr("data-filter"); 31 $("#filters").append("<input name='fq' type='hidden' value='" + filter + "¤' >"); 32 $("#searchform").submit(); 33 34 }); 35 36 $("#filters").on("click", "a", function () { 37 $(this).prev("input").remove(); 38 $("#searchform").submit(); 39 }); 40 }); 41 </script> 42 43 <div class="searchform"> 44 <form id="searchform" method="GET"> 45 <input id="txtSearch" autocomplete="off" type="search" name="q" value="@query" /> 46 <button type="submit">Search</button> 47 48 @if (!String.IsNullOrEmpty(Request["fq"])) 49 { 50 fq.AddRange(Request
新聞熱點
疑難解答