Skip to main content.
home | support | download

Back to List Archive

Re: Making SWISH::API->new() accept a list?

From: Lars Kellogg-Stedman <lars(at)not-real.oddbit.com>
Date: Tue Nov 30 2004 - 23:37:00 GMT
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--8323328-380117640-1101857727=:5819
Content-Type: TEXT/PLAIN; charset=US-ASCII

>    SWISH::API->new( join ' ', map { q["$_"] } @list );

Bleah :).

> That's a good idea.  The XS could just look for list being passed in.
> 
> We were talking about this a week or so ago on the developer's list.
> I was suggesting that the index file be a separate object.  So you
> might first create a few indexes and then "attach" them to the main
> swish object.

A good idea, although I'd argue that it should still be possible to pass
filenames in and have the module take care of creating a SWISH::API::Index
object...something like:

  sub new {
    my $self = shift;

    # ... set up object ...

    for (@_) {
      if (ref($_)) {
        $self->add_index_object($_);
      } else {
        my $index = new SWISH::API::Index $_;
        $self->add_index_object($index);
      }
    }
  }
 
>   my $index1 = SWISH::API->new_index( 'index.1' );
>   my $index2 = SWISH::API->new_index( 'index.2' );

I'd go for SWISH::API::Index->new(), myself.  And I'd probably try to do
something about New_Search_Object, too :).

In any case, attached to this message is a diff against 2.4.2 that adds the
following:

  (1) The new() function now takes a perl list:

        $sw = new SWISH::API [ index [, index ] ]

      So you can say:

        $sw = new SWISH::API "index.1";

      Or:

        $sw = new SWISH::API "index.1", "index.2";

      The above calls will add the indexes and call SwishAttach().

  (2) The new() function can be called with an empty parameter list:

        $sw = new SWISH::API;

      In this case, you get a new handle but no indexes.  You can then:

        $sw->addindex("index.1");
        $sw->addindex("index.2");
        $sw->attach;

      There is currently no error checking -- if you never attach(), you
      get a segfault.  It also doesn't look like you can sanely call
      SwishAttach() multiple times, so I think the eventual behavior should
      be to:

        (1) Make queries fail if attach() hasn't been called, and

        (2) Make addindex() and attach() fail if attach() has
            already been called.

      (Where "fail" probably means "throw an exception".)

Please note that this hasn't been heavily tested :).  It works for my
application, which is trivial but does quire handling multiple indexes.

-- Lars

-- 
Lars Kellogg-Stedman <lars@oddbit.com>


--8323328-380117640-1101857727=:5819
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="swish.lks.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.44.0411301835270.5819@wolery.deas.harvard.edu>
Content-Description: 
Content-Disposition: attachment; filename="swish.lks.patch"

ZGlmZiAtcnVOIHN3aXNoLWUtMi40LjIvcGVybC9BUEkueHMgc3dpc2gtZS0y
LjQuMi1sa3MvcGVybC9BUEkueHMNCi0tLSBzd2lzaC1lLTIuNC4yL3Blcmwv
QVBJLnhzCTIwMDQtMDEtMjQgMTM6Mjc6MTAuMDAwMDAwMDAwIC0wNTAwDQor
Kysgc3dpc2gtZS0yLjQuMi1sa3MvcGVybC9BUEkueHMJMjAwNC0xMS0zMCAx
ODoyMTowNy4wMDAwMDAwMDAgLTA1MDANCkBAIC0yNSwyMiArMjUsNDYgQEAN
CiANCiAjIFRoaXMgcmV0dXJucyBTV19IQU5ETEUNCiB2b2lkIA0KLW5ldyhD
TEFTUywgaW5kZXhfZmlsZV9saXN0ICkNCituZXcoQ0xBU1MsIC4uLikNCiAg
ICAgY2hhciAqQ0xBU1MNCi0gICAgY2hhciAqaW5kZXhfZmlsZV9saXN0DQog
DQogICAgIFBSRUlOSVQ6DQogICAgICAgICBTV19IQU5ETEUgaGFuZGxlOw0K
IA0KICAgICBQUENPREU6DQogICAgICAgICBTd2lzaEVycm9yc1RvU3RkZXJy
KCk7DQotICAgICAgICBoYW5kbGUgPSBTd2lzaEluaXQoIGluZGV4X2ZpbGVf
bGlzdCApOw0KKyAgICAgICAgaGFuZGxlID0gKHZvaWQgKilTd2lzaE5ldygp
Ow0KKw0KKyAgICAgICAgaWYgKGl0ZW1zID4gMSkgew0KKyAgICAgICAgICAg
IGludCBjb3VudGVyOw0KKw0KKyAgICAgICAgICAgIGZvciAoY291bnRlcj0x
OyBjb3VudGVyIDwgaXRlbXM7IGNvdW50ZXIrKykgew0KKyAgICAgICAgICAg
ICAgICBjaGFyICppbmRleF9maWxlID0gU3ZQVlgoU1QoY291bnRlcikpOw0K
KyAgICAgICAgICAgICAgICBhZGRpbmRleGZpbGUoaGFuZGxlLCBpbmRleF9m
aWxlKTsNCisgICAgICAgICAgICB9DQorDQorICAgICAgICAgICAgU3dpc2hB
dHRhY2goaGFuZGxlKTsNCisgICAgICAgIH0NCisNCiAgICAgICAgIFNUKDAp
ID0gc3ZfbmV3bW9ydGFsKCk7DQogICAgICAgICBzdl9zZXRyZWZfcHYoIFNU
KDApLCBDTEFTUywgKHZvaWQgKiloYW5kbGUgKTsNCiAgICAgICAgIFN3aXNo
U2V0UmVmUHRyKCBoYW5kbGUsICh2b2lkICopU3ZSVihTVCgwKSkgKTsNCiAg
ICAgICAgIFhTUkVUVVJOKDEpOw0KIA0KK3ZvaWQNCithZGRpbmRleChzZWxm
LCBpbmRleF9maWxlKQ0KKyAgICAgICAgU1dfSEFORExFIHNlbGYNCisgICAg
ICAgIGNoYXIgICAgICAqaW5kZXhfZmlsZQ0KKw0KKyAgICBQUENPREU6DQor
ICAgICAgICBhZGRpbmRleGZpbGUoc2VsZiwgaW5kZXhfZmlsZSk7DQogDQor
dm9pZA0KK2F0dGFjaChzZWxmKQ0KKyAgICAgICAgU1dfSEFORExFIHNlbGYN
CisNCisgICAgUFBDT0RFOg0KKyAgICAgICAgU3dpc2hBdHRhY2goc2VsZik7
DQogDQogdm9pZA0KIERFU1RST1koc2VsZikNCg==
--8323328-380117640-1101857727=:5819--
Received on Tue Nov 30 15:37:06 2004