Solr.NET快速入门(一)

栏目: 数据库 · 发布时间: 8年前

内容简介:Solr.NET快速入门(一)

字典映射和动态字段

Solr dynamicFields可以根据用例不同地映射。 它们可以被“静态地”映射,例如,给定:

<dynamicField name="price_*"  type="integer"  indexed="true"  stored="true"/>

一个特定的dynamicField实例可以映射为:

[SolrField("price_i")]
public decimal? Price {get;set;}

然而,通常需要有更多的灵活性。 您还可以将dynamicFields映射为字典,并使用字段名前缀:

[SolrField("price_")]
public IDictionary<string, decimal> Price {get;set;}

在这种情况下,price_用作实际Solr字段名称的前缀,例如。 使用此映射,Price [“regular”]映射到名为price_regular的Solr字段。

另一个,甚至更灵活的映射:

[SolrField("*")]
public IDictionary<string, object> OtherFields {get;set;}

对于任何其他未映射的字段,它充当全部容器。 例如。 OtherFields [“price_i”]映射到名为price_i的Solr字段。

完全松散的映射

通过使用Dictionary

Startup.Init<Dictionary<string, object>>(serverUrl);
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Dictionary<string, object>>>();
solr.Add(new Dictionary<string, object> {
  {"field1", 1},
  {"field2", "something else"},
  {"field3", new DateTime(2010, 5, 5, 12, 23, 34)},
  {"field4", new[] {1,2,3}},
});

当获取作为Dictionary

ISolrOperations<Dictionary<string, object>> solr = ...
ICollection<Dictionary<string, object>> results = solr.Query(SolrQuery.All);
bool inStock = (bool) results[0]["inStock"];

自定义映射

您可以通过实现IReadOnlyMappingManager接口对自己的映射机制进行编码。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Don't Make Me Think

Don't Make Me Think

Steve Krug / New Riders Press / 18 August, 2005 / $35.00

Five years and more than 100,000 copies after it was first published, it's hard to imagine anyone working in Web design who hasn't read Steve Krug's "instant classic" on Web usability, but people are ......一起来看看 《Don't Make Me Think》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具