5
  1. I want to use QueryResponse.getBeans()
  2. I have classes defined in another project which does not have solr dependencies, so I can't use @Field on them

Is there an xml (or other externalized) alternative to @Field?

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140

2 Answers2

3

Afaik there is no externalized standard way to this.

But there are probably some ways to achieve what you are trying to do:

  1. Copy solely the annotation to the different project with the same package. And annotate your bean.
  2. It is not possible to set annotations at runtime. These can be solved by using something like a adapter pattern(described here). I would prefer this because in the matter of style it seems to be a pretty clean solution.

Here is the issue about it: Solr are adding more flexibility.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
fyr
  • 20,227
  • 7
  • 37
  • 53
  • I don't think an adapter can help here. How do you propose to use it? – Bozho Jul 09 '11 at 15:54
  • You inherit the adapter from your others project class and in the adapter you add a method to set a bean delivered by solr. The class to call getBeans adds the annotations to its fields. – fyr Jul 09 '11 at 16:29
  • but that would mean I will have to copy the entire structure? Which is exactly what I'm trying to avoid – Bozho Jul 09 '11 at 16:32
  • exactly that is the caveat on this option. If you want to avoid the copy maybe option 1 will give you a solution. But i agree that every of the proposed methods is more like a dirty hack. But as i said there is no standard way. The jvm doesnt support runtime methods to set annotations :/ – fyr Jul 09 '11 at 18:48
  • well, actually it may support them by a compiler plugin or an agent (aspectj), but it's also a hack. I'm thinking of extending the QueryResponse class and provide my own externalizable configuration – Bozho Jul 09 '11 at 19:00
  • 1
    Another option would be to add a custom DocumentObjectBinder which uses e.g. only reflection to map index fields to attributes inside the class in the other project. – fyr Jul 09 '11 at 19:04
  • I updated your answer with a link to the ticket I opened at Solr. They are making improvements. – Bozho Dec 15 '11 at 21:01
-1

I think this may help you.

http://wiki.apache.org/solr/SchemaXml

In the past I have also created my own versions of the classes from the other project and then provided a transformer to build my versions from the external classes I depend on. This transformer can work both ways and is easily tested.

James DW
  • 1,815
  • 16
  • 21
  • the link is about the schema. How is it related to the mapping of results? And which section should I look into. The two version of the classes is my current solution, but it's a duplication I'd like to avoid – Bozho Jul 08 '11 at 12:41
  • 1
    This doesn't answer the question. Please delete this answer. – Mauricio Scheffer Jul 08 '11 at 14:38