happypeter / haoduoshipin

好多视频
http://haoduoshipin.com
236 stars 88 forks source link

search 搜索 swiftype #327

Closed happypeter closed 9 years ago

happypeter commented 9 years ago

https://swiftype.com/engines/hdsp

这个看上去是非常简单的。

billie66 commented 9 years ago

swiftype 文档地址

https://swiftype.com/documentation/tutorials

先用一下 swiftype crawler 搜索,看看效果

https://swiftype.com/documentation/crawler_quick_start

不满意的话,再改 swiftype api 搜索,貌似也是用的 Elasticsearch

https://swiftype.com/documentation/overview

billie66 commented 9 years ago

免费用户只能创建一个引擎

首先要设置搜索引擎,点击 Install search engine 大方块,开始配置,配置完成之后会生成所要安装的脚本代码,把代码粘贴到带有搜索框的页面中,搜索框的格式

<form>
  <input type='text' id='st-search-input' class='st-search-input'/>
</form>

虽然安装了脚本代码,但是这时还不能搜索,还需要点击激活按钮,搜索才能在网站中生效。

现在的搜索结果很不理想,swiftype 把网站中的所要页面都做了索引,如用户主页等,因此会出现很多干扰信息,swifttype 提供了白名单和黑名单机制,看看能不能优化搜索结果

billie66 commented 9 years ago

免费用户可以索引的页面数量 500 pages

https://swiftype.com/questions/swiftype-isnt-indexing-my-entire-site-how-many-pages-will-swiftype-index

billie66 commented 9 years ago

综合一下,还是选择 swiftype api 搜索,有以下优点:

happypeter commented 9 years ago

对,api 拥有更强的灵活性

billie66 commented 9 years ago

document 字段类型

https://swiftype.com/documentation/tutorials/schema_design

搜索选项

https://swiftype.com/documentation/searching

查询解析器规则

http://lucene.apache.org/core/3_0_3/queryparsersyntax.html

Ruby on Rails demo

https://swiftype.com/documentation/tutorials/rails

billie66 commented 9 years ago

搜索结果会返回一个 highlight 字段,给每个字段中的第一个匹配项加 <em> 标签,有点奇怪,比方说有一个 title 字段,其值为 “Rails is a web framework, rails is powerful”,若搜索 rails,则返回结果:

"highlight"=> {"title"=>"<em>Rails</em> is a web framework, rails is powerful"}

虽然 rails 有两个匹配项,但是只是高亮第一个匹配项。

以上情况,swiftype 文档说明

Snippets and Highlighting Any fields that are queried during a search will return the top match (if any) in the highlight property of the results. All snippets in this form have HTML entities from the original text encoded. Actual highlighting is specified using (unencoded) tags.

happypeter commented 9 years ago

YC 也有一个类似的服务:http://www.algolia.com/

billie66 commented 9 years ago

algolia 的界面看着很酷,免费版也支持 1000 个 documents

billie66 commented 9 years ago

代码已经 push 到 github

billie66 commented 9 years ago

创建新视频之后,会自动索引视频信息到 swifype。代码已经部署,搜索还挺快的