lucene-solr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean Baptiste Pionnier (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields
Date Fri, 20 Nov 2009 11:13:39 GMT

    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512
] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:12 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  {{org.apache.solr.client.solrj.beans.DocumentObjectBinder.
 toSolrInputDocument()}}
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null &&
field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ
repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another
to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.
 toSolrInputDocument()
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null &&
field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ
repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another
to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method
with a field name, field value and an optional boost.  In case of dynamic fields, if field
names are known upfront, then caller of this method just passes in the right name and it automatically
works.
> This does not go well with users who use {{@interface Field}} annotations for automatic
binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field
("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should
exhibit the same behavior.  The field {{value}} currently supported are - primitive, array,
collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for
which {{addField}} method is called, is of dynamicField type (which can be derived from the
field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the
correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message