Re: Help - Relationships, Bindings, w/Full Text Search
Re: Help - Relationships, Bindings, w/Full Text Search
- Subject: Re: Help - Relationships, Bindings, w/Full Text Search
- From: Chuck Hill <email@hidden>
- Date: Wed, 27 Sep 2006 09:52:03 -0700
On Sep 27, 2006, at 6:29 AM, Drew Thoeni wrote:
I implemented objectFromRawRow and am baffled by this exception:
java.lang.IllegalArgumentException: Raw row {REPORT_ENTRY_ID =
130; } does not contain primary key information for entity ReportEntry
However, the NSDictionary returned from rawRowsForSQL is correct;
there is one row and it's primary key is REPORT_ENTRY_ID = 130. So,
I'm curious why, if the row is returned, the dictionary is correct,
the key is identified, and the value for the key is correct, the
objectFromRawRow would be throwing the exception.
My bad. I should have mentioned this. EOF works on attribute names
not column names. So it is looking for a dictionary entry with the
key of the PK attribute name in your model. I recall this is "oid".
This is what the fourth parameter to rawRowsForSQL is for, "keys -
array of Strings corresponding to the SELECT list; these will be used
as the keys in the result dictionaries; use null for default
naming." Default naming means "column names as given in the SELECT".
Here's the code:
private void performSearch( String searchString ) {
// REPORT_ENTRY_ID is defined as the PK (and only PK for this
table) in EOModel and in the database.
String sqlString = "select REPORT_ENTRY_ID from REPORT_ENTRY where
SATISFIES(report_entry_full_text, " + searchString + ");";
// In the example search producing the above exception, only one
row is returned.
NSArray result = EOUtilities.rawRowsForSQL( ec, "segment_report",
sqlString, null);
Try this instead:
NSArray result = EOUtilities.rawRowsForSQL( ec, "segment_report",
sqlString, new NSArray("oid"));
Chuck
ReportEntry tempItem = null;
NSMutableArray tempList = new NSMutableArray();
if( null != result && result.count() > 0 )
{
for( int i=0; i < result.count(); i++ )
{
tempItem = (ReportEntry)EOUtilities.objectFromRawRow( ec,
"ReportEntry", (NSDictionary)result.objectAtIndex(i) );
tempList.addObject( tempItem );
tempItem = new ReportEntry();
}
}
setSearchResultList( tempList );
}
On Sep 26, 2006, at 1:10 PM, Chuck Hill wrote:
Hi Drew,
On Sep 25, 2006, at 7:56 PM, Drew Thoeni wrote:
On Sep 25, 2006, at 5:21 PM, Chuck Hill wrote:
On Sep 24, 2006, at 8:18 AM, Drew Thoeni wrote:
I'm using Frontbase's full text index to successfully return
rows. The main goal is to allow users to search large-full text
columns, returning enterprise objects. I have broken this into
three specific requirements as I can't seem to fulfill more
than two, regardless of approach.
1) Search for strings in a large text column using Frontbase's
full text index (requires SQL such as "...where SATISFIES
(full_text_index, search_string)...".
2) Allow user input and pass this as a parameter to the
fileSpec for a query.
3) Create or return EOs so as to have relationship information
so as to provide key value coding to related tables.
It seems I'm missing something as I can only meet two of the
three above at a time. Here are the options performed so far:
A) Using rawRowsForSQL I can do 1 and 2 above. I have converted
the results into enterprise objects but do not know how to
perform an addObjectToBothSidesOfRelationshipWithKey which
would allow access to related objects (such as code tables).
I am not following what your problem here is. If you have an eo
as converted from (1) and (2) why can you not do
eo.addObjectToBothSidesOfRelationshipWithKey(tag, "tag")?
Yep. A fair point and there's a good chance I'm looking at this
cockeyed. A more detailed explanation: I'm pulling back Report
rows using rawSQL. Once I get the rows back, I'm iterating
through, creating Report objects and setting their values based
on data retrieved in the SQL query.
OK, that sounds really wrong.
I then add these all to an array and can display them nicely in a
WORep
I am not pulling back object IDs (primary and foreign keys) in
the SQL query because the OIDs are not part of the EOModel;
Surely the OIDs are part of the EOModel. I will assume that you
mean they are not class properties of the entities, but that they
are defined in the EOModel. Otherwise, I can't see how EOF could
work.
So, as they are part of the EOModel, you _can_ pull back the
values using your rawRowsForSQL. So what you want to do is to
pull back the OID, and then use EOUtilities.objectFromRawRow to
convert raw rows into EOs. Note that any data you pull back with
the rawRowsForSQL will _not_ be used by objectFromRawRow. So,
unless you need to display some of that information before
converting raw rows into EOs, you can make it more efficient by
just selecting the OID. What is usually done is to select some of
the data and the OID and display the partial data. Once the user
indicates which rows will be used in a process, turn those rows
into EOs.
One potential issue with this is that objectFromRawRow works on
one EO at a time, so for large numbers of EOs, that is a lot of
trips to the database. IIRC, you can construct a manual array
fault and have EOF fetch them all in at once, though I don't
recall the methods at the moment. Let me know if you need this.
Chuck
I can't set their values. So, given my knowledge (admittedly
limited), I don't have foreign keys in Report with which I could
addObjectToBothSidesOfRelationshipWithKey.
If I had these as complete objects I'd do as you suggest
aReport.addObjectToBothSidesOfRelationshipWithKey( aCompetitor,
"toCompetitor") and that would work great.
I'm sure there's some way of accomplishing this that I have not
considered. I've checked this list, Frontbase's list, and
Practical WebObjects. Perhaps I'm looking for the wrong things.
B) Using objectsWithFetchSpecificationAndBindings I can do 2
and 3 above. But EOModeler does not allow the "SATISFIES" term,
even when typing it into the fetchSepc in "Use Raw SQL
Expression."
You would need to extend EOF to do that. Pierre Bernard's
qualifiers would be the place to start for this.
C) Using a stored procedure I can do 1 and 3 above. However, I
do not see a way of passing a user-defined search into the
store procedure from WebObjects.
No ideas on that.
Perhaps there is a much better and non-database specific way to
quickly search large text fields with features such a stemming,
wildcards, etc.
For a non-database specific way, see http://lucene.apache.org/
The basic idea is much like handling the rawsRowsFromSQL result:
you index the text and store the entity name and PK with the
text. Do a Lucene search, and convert the entity name and PK
back into an EO. It takes a while to wrap your head around it.
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve
specific problems. http://www.global-village.net/products/
practical_webobjects
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve
specific problems. http://www.global-village.net/products/
practical_webobjects
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems. http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Help - Relationships, Bindings, w/Full Text Search (From: Drew Thoeni <email@hidden>) |
| >Re: Help - Relationships, Bindings, w/Full Text Search (From: Chuck Hill <email@hidden>) |
| >Re: Help - Relationships, Bindings, w/Full Text Search (From: Drew Thoeni <email@hidden>) |
| >Re: Help - Relationships, Bindings, w/Full Text Search (From: Chuck Hill <email@hidden>) |
| >Re: Help - Relationships, Bindings, w/Full Text Search (From: Drew Thoeni <email@hidden>) |