|
Compass has support for direct Resource persistence. It does requires resource mapping definition for any resource saved in Compass (using the alias as the connection between the resource and the mappings), since each resource must have at least one resource id mappings. You can then add as many resources properties that you want (they can have resource-property mappings or not).
Have a look at the test source tree, under org/compass/core/test/resource for examples. (by the way, the forum is a better place for questions like this one). Hmm, I see, but I would expect that Compass knows what the id field is when calling
org.compass.core.Property resourceIdProp = session.createProperty("myIdField", "someIdValue", org.compass.core.Property.Store.YES, org.compass.core.Property.Index.UN_TOKENIZED); and I do not need a mapping file anymore. I see this as a nice feature, because then you can control the mapping completely from code. Sadly, the way Compass in built currently, it most know in advance the Property that will act as an id of the Resource. Naturally, this can be changed, but I think that the id will be known in advance most if not all of the time. Is there a case for you where you do not know the id property name?
Also, from your code, Compass still does not know that resourceIdProp is the id, there will have to be something like Resource#addIdProperty, and Resource will have to keep track what properties act as the ids. Any comments regarding this one, or can I close this?
When a property is programmatically added it does not appear in the resource mapping information and hence property name prefixed searches cannot happen.
Also even though the property can be marked searchable it is only searchable as part of the "all" field. If we remove the all field then searches matching the programmatically created property do not appear in the result. RSEM File: <compass-core-mapping> <resource alias="alias1"> CODE SNIPPET: org.compass.core.Resource r = session.createResource("alias1"); r.addProperty("id", key.getResourceIdentifier()); r.addProperty(session.createProperty("testPropName", QUERY RELATED CODE SNIPPET: CompassSession session = indexCompass.openSession(); When not defining the property in advance within the mapping file, you can't use alias.[something]. You can still use [something] to search for it without the alias prefix.
Thanks for the reply
![]() I am very new to both compass and Lucene and hence please be patient with me. Even <propertyname>:<term> doesnt work if i do not have the "all" field. For e.g. if there are two properties A and B. A is part of the .cpm file i.e. is part of the mapping but property B is added programmatically. Then if the mapping is defined without the use of "all" then searches like "B:abc" do not return any result even if there are potential matches. But the searches like "A:abc" do work fine. On the other hand if I enable the use of "all" then both "B:abc" and "A:abc" work absolutely fine. May be I am missing something here. I would really appreciate some help on this. As this could be a potential issue for my application as I would prefer not to use the "all" field. as the properties have their individual ranking which I would want to be preserved. Thanks in advance for your help. Can we move this to the forum?
|
or the MarshallingStrategy:
public void create(Object object) throws CompassException { Resource resource = marshallingStrategy.marshall(object); <----- what if object already is a Resource? searchEngine.create(resource); ResourceIdKey key = new ResourceIdKey(mapping, resource); firstLevelCache.set(key, object); }