我想进行实现以下项目的搜索。
现在,我已经通过Regex实施了所有这些,这远非涵盖所有内容,我想知道我可以为此使用elasticsearch多少:
同义词
我的理解是,当创建索引时,这将实现。
indexSettings.Analysis.TokenFilters.Add(“同义词”,新的同义词tokenfilter {synonyms = new [] {“ tire => tire”,“ aluminum => aluminum”},ignorecase = true,true,true,tokenizer = tokenizer =“ whitespace” whitespace“ whitespace”}));
但是我还需要包括复数吗?或者,
奇异的单词(鞋子和鞋子应该是一场相同的比赛)
这是否意味着我需要将“鞋子”放在同义词列表中?还是还有另一种方式?
应允许小拼写错误,替代和遗漏
因此,“汽车”,“汽车”或“汽车”将匹配。我不知道这是否有可能。
忽略所有停止单词
现在,我正在通过正则删除所有“','',“我的”等
我所有的搜索词都是简单的英语单词和数字;不允许其他允许。
所有这些都是可能的 配置/编写自定义分析仪 在Elasticsearch中。依次回答每个问题:
同义词
同义词可以在索引时间,搜索时间或同时应用。无论您选择哪种方法,都需要考虑权衡取舍
还需要考虑同义词列表的大小以及它的频率(如果有的话)变化。我会考虑尝试两者,并确定哪种最适合您的情况和要求。
奇异的单词(鞋子和鞋子应该是一场相同的比赛)
您可以考虑使用 茎 使用算法或基于词典的词干将复数和奇异的单词减少到其根部形式。也许从 英国雪球茎 看看它如何为您服务。
您还应该考虑是否还需要索引原始单词表单,例如确切的单词匹配是否应该比其根部形式上的词干单词高?
应允许小拼写错误,替代和遗漏
考虑使用可以使用的查询 模糊 处理错别字和拼写错误。如果索引数据中存在拼写错误,请在索引之前考虑某种形式的消毒。按照所有数据存储,垃圾进口,垃圾出去:)
忽略所有停止单词
使用 英语停止令牌过滤器 删除停止单词。
将所有这些放在一起,一个示例分析仪可能看起来像
void Main(){ var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); var defaultIndex = "default-index"; var connectionSettings = new ConnectionSettings(pool) .DefaultIndex(defaultIndex); var client = new ElasticClient(connectionSettings); if (client.IndexExists(defaultIndex).Exists) client.DeleteIndex(defaultIndex); client.CreateIndex(defaultIndex, c => c .Settings(s => s .Analysis(a => a .TokenFilters(t => t .Stop("my_stop", st => st .StopWords("_english_", "i've") .RemoveTrailing() ) .Synonym("my_synonym", st => st .Synonyms( "dap, sneaker, pump, trainer", "soccer => football" ) ) .Snowball("my_snowball", st => st .Language(SnowballLanguage.English) ) ) .Analyzers(an => an .Custom("my_analyzer", ca => ca .Tokenizer("standard") .Filters( "lowercase", "my_stop", "my_snowball", "my_synonym" ) ) ) ) ) .Mappings(m => m .Map<Message>(mm => mm .Properties(p => p .Text(t => t .Name(n => n.Content) .Analyzer("my_analyzer") ) ) ) ) ); client.Analyze(a => a .Index(defaultIndex) .Field<Message>(f => f.Content) .Text("Loving those Billy! Them is the maddest soccer trainers I've ever seen!") );}public class Message{ public string Content { get; set; }}my_analyzer 为上述生成以下令牌
{ "tokens" : [ { "token" : "love", "start_offset" : 0, "end_offset" : 6, "type" : "<ALPHANUM>", "position" : 0 }, { "token" : "those", "start_offset" : 7, "end_offset" : 12, "type" : "<ALPHANUM>", "position" : 1 }, { "token" : "billi", "start_offset" : 13, "end_offset" : 18, "type" : "<ALPHANUM>", "position" : 2 }, { "token" : "them", "start_offset" : 20, "end_offset" : 24, "type" : "<ALPHANUM>", "position" : 3 }, { "token" : "maddest", "start_offset" : 32, "end_offset" : 39, "type" : "<ALPHANUM>", "position" : 6 }, { "token" : "football", "start_offset" : 40, "end_offset" : 46, "type" : "SYNONYM", "position" : 7 }, { "token" : "trainer", "start_offset" : 47, "end_offset" : 55, "type" : "<ALPHANUM>", "position" : 8 }, { "token" : "dap", "start_offset" : 47, "end_offset" : 55, "type" : "SYNONYM", "position" : 8 }, { "token" : "sneaker", "start_offset" : 47, "end_offset" : 55, "type" : "SYNONYM", "position" : 8 }, { "token" : "pump", "start_offset" : 47, "end_offset" : 55, "type" : "SYNONYM", "position" : 8 }, { "token" : "ever", "start_offset" : 61, "end_offset" : 65, "type" : "<ALPHANUM>", "position" : 10 }, { "token" : "seen", "start_offset" : 66, "end_offset" : 70, "type" : "<ALPHANUM>", "position" : 11 } ]}我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa
我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll