From: Kal A. <ka...@te...> - 2004-08-19 21:46:20
|
On Thu, 2004-08-19 at 21:27, Bret Cohen wrote: > Hi Kal, > > Thanks once again for your quick response. > > Let me make sure I understand all of this > correctly: > > Normally for tolog queries, the tolog > parser reads the topics from an XTM (or LTM) > file into Topic objects in memory, > then passes the appropriate Topic object to > the predicate implementation. > Not quite. You have to pass a TopicMap instance to the tolog QueryEvaluator when you construct it. That is the topic map that will be queried. > For parameterized queries, my own application > has to read the topics from the XTM file > into Topic objects, which can then be > passed to the predicate implementation. > > To read topics into memory, I need to use > something like the readTopicMap() method > on p. 38 of the Dev. Guide PDF > (and also used within the IndexingExample) > > At that point I could do a search of the > Topic objects in memory to find the one > to be passed in to the parametarized query. > Thats all correct, with the addition that you can pass the same TopicMap handle to the QueryEvaluator. > That search could be done via one of the indices > (or, presumably, by another topic query). > Indeed! > This leads to two questions: > > 1. If the in-memory representation is out > of sinc with the XTM file. (For example, > if a new topic has been added to memory, > but not yet serialized to XTM), > on which will tolog perform the query: > the XTM file, or the in-memory representation? > The query evaluator *always* queries an in-memory representation. If you make sure that you use the same TopicMap handle, then the query evaluator will stay in sync, because all of the indexes it uses are automatically updated as you modify the topic map. Of course, if you are connecting to a persistent store, then you could have two different handles to the same persistent topic map, but thats just an added complication ;-) > 2. Is it always better to use an Index > when an appropriate one is available > than a Tolog Query (for example: to find > all topics of a certain type)? > It depends. Most of the basic predicate implementations make use of the indexes under the hood so there is no great difference in performance (just a slight overhead for parsing the query). However in some cases you may find it more convenient in your code to use the index instead of having to construct a query string and process the results set. For example if you know the ID of the topic, you can use TopicMap.getObjectByID() which returns the Topic object directly whereas using the query interface you would have to write a bit of extra code to construct the query string and extract the result. When it comes to more complex queries you will most certainly find it more convenient to use the tolog query engine instead - at the moment there is no optimisation performed, so you have to be careful how you write the queries - predicates are evaluated from left-to-right so try and put the predicates that narrow down the results set the most as far to the left in your query as you can. A future version of TM4J will probably include some heuristics for optimising queries before executing them (the stubs are in the code, there is just no implementation yet). Hope that helps! Cheers, Kal -- Kal Ahmed <ka...@te...> techquila |