solr index for multi-valued multi-type field

ⅰ亾dé卋堺 提交于 2019-12-20 05:51:34

问题


I am indexing a collection of xml document with the next structure:

<mydoc>
  <id>1234</id>
  <name>Some Name</name>
  <experiences>
    <experience years="10" type="Java"/>
    <experience years="4" type="Hadoop"/>
    <experience years="1" type="Hbase"/>
  </experiences>
</mydoc>

Is there any way to create solr index so that it would support the next query:

find all docs with experience type "Hadoop" and years>=3

So far my best idea is to put delimited years||type into multiValued string field, search for all docs with type "Hadoop" and after that iterate through the results to select years>=3. Obviously this is very inefficient for a large set of docs.


回答1:


I think there is no obvious solution for indexing data coming from the many-to-many relationship. In this case I would go with dynamic fields: http://wiki.apache.org/solr/SchemaXml#Dynamic_fields

Field definition in schema.xml:

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

So, using your example you would end up with something like this:

<mydoc>
  <id>1234</id>
  <name>Some Name</name>
  <experience_Java>10</experience_Java>
  <experience_Hadoop>4</experience_Hadoop>
  <experience_Hbase>1</experience_Hbase>
</mydoc>

Then you can use the following query: fq=experience_Java:[3 to *]



来源:https://stackoverflow.com/questions/16370466/solr-index-for-multi-valued-multi-type-field

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