You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Billy Newman <ne...@gmail.com> on 2012/10/22 21:26:36 UTC
De-normalize one-to-many, cannot default multivalued field
Hello again,
I am trying to figure out the best way to de-normalize some
one-to-many values so that I can store them into my index. I am using
the DIH and I have the following data coming in:
<root>
<style>
<name>Style 1</name>
<title> Style One</title>
<description> Style 1 description</description>
</style>
<style>
<name>Style 2</name>
<title> Style Two</title>
<description> Style 2 description</description>
</style>
<style>
<name>Style 3</name>
<title> Style Three</title>
<description> Style 3 description</description>
</style>
...
</root>
I have tried making three fields: style_name, style_title,
style_description and setting them to multivalued. This works until
one of fields (name,title,description) does not have a value.
I.E.:
<root>
<style>
<name>Style 1</name>
<title> Style One</title>
<description> Style 1 description</description>
</style>
<style>
<name>Style 2</name>
<description> Style 2 description</description>
</style>
<style>
<name>Style 3</name>
<title> Style Three</title>
</style>
...
</root>
Now it is hard to tell which name/title/description go together when querying.
I tried setting the 'default' attribute of each, but the default is
only applied of there are 0 values for the field. Is there a way when
using the DIH to replace 'null' or missing values with a default, such
that I can ensure that I always have the same number of values in each
multivalued field?
The only other thing I can think to do is to have parent-child
relationship and use a 'join'.
Any ideas?
Thanks,
Billy
Re: De-normalize one-to-many, cannot default multivalued field
Posted by Chris Hostetter <ho...@fucit.org>.
I don't know if there is an easy way to address the key crux of your
question...
: only applied of there are 0 values for the field. Is there a way when
: using the DIH to replace 'null' or missing values with a default, such
: that I can ensure that I always have the same number of values in each
: multivalued field?
...but one other idea i'd like to put out there for you to consider is to
change how you think about your index, so that instead of having one
document per "root" (in your sample data) you create one document per
"style" -- this would let you query on individual styles very easily, and
you could use Grouping when you need to find "root" products...
https://wiki.apache.org/solr/FieldCollapsing
...I don't know enough about your usecase to know if this approach would
make your life easier or more complicated, but it's something to consider.
-Hoss