SourceForge.net Logo
Main Overview Wiki Issues Forum Build Fisheye
Issue Details (XML | Word | Printable)

Key: CMP-233
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Shay Banon
Reporter: Jonas Van Poucke
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Compass

Mapping required when adding property with createProperty(name, value, store, index);

Created: 26/Jul/06 05:03 AM   Updated: 28/Sep/07 05:04 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None


 Description  « Hide
When I add a Property with
session.Property createProperty(String name, String value, Property.Store store, Property.Index index);
Compass still requires a mapping for the property with that name. Didn't I set the mapping programatically?

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Jonas Van Poucke added a comment - 26/Jul/06 05:08 AM
I think a solution would be to provide a create(Resource resource) instead of create(Object root) [and equivalents] in DefaultCompassSession
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); }

Shay Banon added a comment - 26/Jul/06 06:28 AM
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).


Jonas Van Poucke added a comment - 26/Jul/06 07:48 AM
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.
Do not misunderstand, I think having a mapping file is an advantage, but I also think programatic configuration is complementary.


Shay Banon added a comment - 26/Jul/06 08:40 AM
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.


Shay Banon added a comment - 28/Jul/06 03:00 PM
Any comments regarding this one, or can I close this?

arsee added a comment - 18/Sep/07 03:15 PM
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:
<?xml version="1.0"?>
<!DOCTYPE compass-core-mapping PUBLIC
"-//Compass/Compass Core Mapping DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd">

<compass-core-mapping>

<resource alias="alias1">
<resource-id name="id" />
<resource-property name="namespace" store="yes" index="un_tokenized" />
<resource-property name="resourceId" store="yes" index="no"/>
<resource-property name="resourceName" store="yes" index="un_tokenized" />
<resource-property name="resourceCanonicalpath" store="yes" index="no"/>
<resource-property name="rootObjectType" store="yes" index="no"/>
<resource-property name="rootObjectId" store="yes" index="no"/>
</resource>
</compass-core-mapping>

CODE SNIPPET:

org.compass.core.Resource r = session.createResource("alias1");

r.addProperty("id", key.getResourceIdentifier());
r.addProperty("namespace", "defaultnamespace");
r.addProperty("resourceId", key.getResourceIdentifier());
r.addProperty("resourceName", key.getName());
r.addProperty("resourceCanonicalpath", key.getCanonicalPath());

r.addProperty(session.createProperty("testPropName",
"testPropValue", Property.Store.YES,
Property.Index.TOKENIZED, Property.TermVector.WITH_POSITIONS_OFFSETS)); //adding a field with name "testPropName"

QUERY RELATED CODE SNIPPET:

CompassSession session = indexCompass.openSession();
CompassQuery query = null;
CompassQueryBuilder queryBuilder;
CompassTransaction tx = null;
try { tx = session.beginTransaction(); queryBuilder = session.queryBuilder(); query = queryBuilder.term("alias1.testPropName", searchTerm); // the code fails here with the following : // java.lang.IllegalArgumentException: Failed to find mapping for alias [alias1] and path [alias1.testPropName] CompassHits hits = query.hits(); tx.commit(); } catch (CompassException ce) { if (tx != null) tx.rollback(); } catch (Exception e) { System.out.println(e.getMessage()); if (tx != null) tx.rollback(); }
finally { session.close(); }


Shay Banon added a comment - 19/Sep/07 03:26 PM
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.

arsee added a comment - 20/Sep/07 04:57 PM
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.


arsee added a comment - 20/Sep/07 04:58 PM
Without the use of alias it doesnt throw an exception but it also doesnt retrieve the result.

Shay Banon added a comment - 28/Sep/07 05:04 PM
Can we move this to the forum?