Branch: Tag:

2001-06-23

2001-06-23 00:21:09 by Johan Schön <js@opera.com>

Added get_filter_fields(), which lists the field names the filters are capable of emitting.

Rev: lib/modules/Search.pmod/Filter.pmod/PlainText.pmod:1.6
Rev: lib/modules/Search.pmod/module.pmod:1.16

1:   // This file is part of Roxen Search   // Copyright © 2000,2001 Roxen IS. All rights reserved.   // - // $Id: module.pmod,v 1.15 2001/06/22 01:28:35 nilsson Exp $ + // $Id: module.pmod,v 1.16 2001/06/23 00:21:09 js Exp $    - private mapping filters; + private mapping filter_mimetypes; + private multiset filter_fields;    - // void create() - // { - // foreach(values(Search.Filter), program filter) - // { - // Search.Filter.Base tmp=filter(); - // foreach(tmp->contenttypes || ({ }), string mime) - // filters[mime]=tmp; - // } - // } -  +    private void get_filters()   { -  filters=([]); +  filter_mimetypes=([]); +  filter_fields=(<>);    foreach(values(Search.Filter), object filter) -  +  {    foreach(filter->contenttypes || ({ }), string mime) -  filters[mime]=filter; +  filter_mimetypes[mime]=filter; +  +  foreach(filter->fields || ({ }), string field) +  filter_fields[field]=1;    } -  + }      Search.Filter.Base get_filter(string mime_type)   { -  if(!filters) +  if(!filter_mimetypes)    get_filters(); -  if(!filters[mime_type]) return 0; -  return filters[mime_type]; +  if(!filter_mimetypes[mime_type]) return 0; +  return filter_mimetypes[mime_type];   }      mapping(string:Search.Filter.Base) get_filter_mime_types()   { -  if(!filters) +  if(!filter_mimetypes)    get_filters(); -  return filters; +  return filter_mimetypes;   }    -  -  - // --- Page Ranking Algorithms ------------ -  - float entropy(array(string) page_words) { -  mapping(string:int) words=([]); -  foreach(page_words, string word) -  words[word]=1; -  return (float)sizeof(words)/(float)sizeof(page_words); + array(string) get_filter_fields() + { +  if(!filter_fields) +  get_filters(); +  return indices(filter_fields);   } -  -  - // A normal page has an entropy value around 0.5, so the result x should probably be - // remapped to abs(x-0.5) or even 1-abs(x-0.5) -  +