How do I pass multiple “bq” arguments to LocalParams in SolrNet?

感情迁移 提交于 2020-01-06 19:35:31

问题


LocalParams is really just a Dictionary<string, string> behind the scenes.

However, I want to pass multiple Boost Queries, which use the key "bq". Obviously, any attempt to add my second "bq" key will fail with An item with the same key has already been added.

var lp = new LocalParams();
lp.Add("bq", "ContentType:Update^3.0");
lp.Add("bq", "ContentType:Comment^0.5"); // Error occurs here...

What's the trick to passing multiple Boost Queries (or multiple anything, really)...


回答1:


The comment above set me onto ExtraParams.

I thought it wouldn't work since that was a Dictionary<string, string> (thus leaving me in the same situation), but the actual property definition is IEnumerable<KeyValuePair<string, string>>. It's just set to a Dictionary<string,string> in the constructor.

So I did this:

var extraParams = new List<KeyValuePair<string, string>>();
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeQuery^10"));
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeOtherQuery^10"));

var options new new QueryOptions();
options.ExtraParams = extraParams; //Since my List implements the right interface

solr.Query(myQuery, options)

My testing shows that it works as intended.



来源:https://stackoverflow.com/questions/29147725/how-do-i-pass-multiple-bq-arguments-to-localparams-in-solrnet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!