RE: [Zope-dev] More ZCatalog Stuff.

2001-02-27 Thread Toby Dickenson

 I am assuming that the code you provided goes into a
 manage_addCustomIndex method that is part of a CustomIndex
 Python Product.

hehehehe, nothing so general-purpose as that ;-)
 
  You will need to implement a subclass derived from one of 
 the standard
  indexes to provide your custom indexing policy, whatever that is.
 
 Can you provide the code for your custom KeywordIndex, so I
 have a starting point? I realize yours subclasses a
 KeywordIndex, and I probably need to subclass a TextIndex,
 but it would still probably help. I can integrate and hack
 on other peoples code better than I can write my own from
 scratch.


from SearchIndex.UnKeywordIndex import UnKeywordIndex, MV, intSet
from types import ListType, TupleType

class UnTrackingIndex(UnKeywordIndex):

meta_type = 'Tracking Properties Index'

"""Like a Keyword Index, only it indexes tracking properties
"""

def __init__(self,question):
id = 'tracking_'+unicode(question).encode('unicode-escape')
self.question = question
UnKeywordIndex.__init__(self,id)

def index_object(self, i, obj, threshold=None):
""" index an object 'obj' with integer id 'i'"""

index = self._index
unindex = self._unindex

try:
kws = obj.tracking_answers(self.question)
if type(kws) not in [type([]),type(())]:
raise ValueError('Indexing a tracking property set of
inappropriate type %r' % type(kws))
except:
kws = (MV,)

# index each item in the sequence
for kw in kws:
set = index.get(kw)
if set is None:
index[kw] = set = intSet()
set.insert(i)

unindex[i] = tuple(kws)

self._index = index
self._unindex = unindex

return 1


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] More ZCatalog Stuff.

2001-02-27 Thread Michael R. Bernstein

Toby Dickenson wrote:
 
 On Mon, 26 Feb 2001 19:00:58 -0800, "Michael R. Bernstein"
 [EMAIL PROTECTED] wrote:
 
 Toby Dickenson wrote:
 
  If you are interested in a short-term hack, it is possible implement
  your own type of index and add it to an existing catalog, without
  having to modify any of the ZCatalog product.
 
 Ok, how? Please keep in mind that I'm more of a designer and
 integrator than a coder.
 
 ZCatalogs are a zopeish wrapper around a zope-neutral catalog object,
 which is stored in the _catalog attribute. That leading underscore is
 a clue that you shouldnt be using it directly, however you need to in
 order to create a custom index. Liek I said, this is a hack.
 
 The main problem is that catalog (and hence ZCatalog) implements a
 factory interface where you specify the name of the index type (for
 example "TextIndex", and it creates the indexing objects.
 
 [snip description and code]

I am assuming that the code you provided goes into a
manage_addCustomIndex method that is part of a CustomIndex
Python Product.

 You will need to implement a subclass derived from one of the standard
 indexes to provide your custom indexing policy, whatever that is.

Can you provide the code for your custom KeywordIndex, so I
have a starting point? I realize yours subclasses a
KeywordIndex, and I probably need to subclass a TextIndex,
but it would still probably help. I can integrate and hack
on other peoples code better than I can write my own from
scratch.

Thanks,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] More ZCatalog Stuff.

2001-02-26 Thread Michael R. Bernstein

Toby Dickenson wrote:
 
 If you are interested in a short-term hack, it is possible implement
 your own type of index and add it to an existing catalog, without
 having to modify any of the ZCatalog product.

Ok, how? Please keep in mind that I'm more of a designer and
integrator than a coder.

Thanks,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] More ZCatalog Stuff.

2001-02-26 Thread Toby Dickenson

On Mon, 26 Feb 2001 19:00:58 -0800, "Michael R. Bernstein"
[EMAIL PROTECTED] wrote:

Toby Dickenson wrote:
 
 If you are interested in a short-term hack, it is possible implement
 your own type of index and add it to an existing catalog, without
 having to modify any of the ZCatalog product.

Ok, how? Please keep in mind that I'm more of a designer and
integrator than a coder.

Today it requires some development effort


ZCatalogs are a zopeish wrapper around a zope-neutral catalog object,
which is stored in the _catalog attribute. That leading underscore is
a clue that you shouldnt be using it directly, however you need to in
order to create a custom index. Liek I said, this is a hack.

The main problem is that catalog (and hence ZCatalog) implements a
factory interface where you specify the name of the index type (for
example "TextIndex", and it creates the indexing objects.

I use the function below to:
1. Use a catalogs factory interface to create a KeywordIndex, to
   allow it a chance to raise an exception if anything is wrong.
2. If nothing goes wrong then I assume it is safe to replace
   the standard KeywordIndex with my custom subclass of a
   KeywordIndex.

def ensure_question_is_indexed(self,question):
question = unicode(question)
cat = self.storage.timeseries_catalog
index = UnTrackingIndex(question)
if index.id not in cat.indexes():
# Add and remove a keyword index using
# the published interface,
# to allow the catalog a chance to complain.
cat._catalog.addIndex(index.id,'KeywordIndex')
cat._catalog.delIndex(index.id)
# Use the private interface to do the real work
cat._catalog.indexes[index.id] = index
cat._catalog._p_changed = 1

You will need to implement a subclass derived from one of the standard
indexes to provide your custom indexing policy, whatever that is.



Toby Dickenson
[EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] More ZCatalog Stuff.

2001-02-25 Thread Christopher Petrilli

Steve Alexander [[EMAIL PROTECTED]] wrote:
 Christopher Petrilli wrote:
 
  
  SMOC :-)
 
 You're in the South Michigan Orienteering Club?
http://www.angelfire.com/mi/SMOC/

Oh sorry, old reference... SMOC = Simple Matter of Code :)

Chris
-- 
| Christopher Petrilli
| [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] More ZCatalog Stuff.

2001-02-24 Thread Chris Withers

"Michael R. Bernstein" wrote:
 
 Hmm. this seems like there ought to be a checkbox next to
 the 'Add Index' form field labeled 'index numbers?'. Or
 maybe a 'Text and Numbers' index as an additional index
 type.

I like these ideas :-)

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )