Announcement Announcement Module
Collapse
No announcement yet.
Adding SOLR @Field annotation to id attribute Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding SOLR @Field annotation to id attribute

    I have the situation where I'm using Roo Mongo entities in conjunction with SOLR. I need to index the Mongo Id in SOLR using annotations but am unable to do so without breaking my model and my unit tests.

    I have multiple entities that subclass a single abstract Mongo super type


    Code:
     @RooJavaBean
    @RooToString
    @RooPlural("AxEntities")
    @RooMongoEntity(identifierType = String.class)
    @RooSerializable
    @RooJson
      public abstract class AbstractEntity {
      @Field
    String domainId;
      @Field
    @DateTimeFormat(style = "M-")
    DateTime created = AxDateUtil.now();
    }
     
      @RooJavaBean
    @RooToString
    @RooPlural("AxRoleEntities")
    @RooMongoEntity(identifierType = String.class)
    @RooSerializable
    @RooJson
      public class AxRole extends AbstractEntity {
         String name;
       String value;
      }
    Since I'm not using JPA and/or Active Record then I can't use the @RooSolrSearchable. Of course my mongo aspect looks like this,

    Code:
     privileged aspect AxEntity_Roo_Mongo_Entity {    
          declare @type: AxEntity: @Persistent;  
    
    @Id
    private String AxEntity.id;
          public String AxEntity.getId() {
           return this.id;
       }
          public void AxEntity.setId(String id) {
           this.id = id;
       }    
      }

    I index my entities in SOLR using generics like this so my code is beautifully oblivious to my model attributes.

    Code:
         public void indexEntities(List<?> entities) throws IOException, SolrServerException {
              if(!entities.isEmpty()) {
                  SolrTemplate solrTemplate = new SolrTemplate(solrServerFactory);
                  solrTemplate.setSolrConverter(solrConverter);
                  solrTemplate.setSolrCore(entities.get(0).getClass().getSimpleName());
                  SolrServer solrServer = solrTemplate.getSolrServer();
                  solrServer.addBeans(entities);
                  solrServer.commit();
              }
          }
    What I need is a way to get the SOLR @Field annotation on the Mongo Id. My thought is to extend RooMongoEntity add-on with an attribute that indicates that the Id field should have the @Field added so the aspect ends up looking like this,

    Code:
    @Id
    @Field
    private String AxEntity.id;
    However, I'm also thinking that this might be a feature that the Spring Roo team might be better off implementing if they think it has wider applicability.

    Perhaps somebody can weigh in on this before I extend this add-on?

    many thanks in advance,
    Mark
Working...
X