home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win-source.exe / myisam / ft_stopwords.c < prev    next >
C/C++ Source or Header  |  2000-09-21  |  2KB  |  79 lines

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.    
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  7.    
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.    
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /* Written by Sergei A. Golubchik, who has a shared copyright to this code */
  18.  
  19. #include "ftdefs.h"
  20.  
  21. typedef struct st_ft_stopwords {
  22.   const char * pos;
  23.   uint   len;
  24. } FT_STOPWORD;
  25.  
  26. static TREE *stopwords3=NULL;
  27.  
  28. static int FT_STOPWORD_cmp(FT_STOPWORD *w1, FT_STOPWORD *w2)
  29. {
  30.   return _mi_compare_text(default_charset_info,
  31.               (uchar *)w1->pos,w1->len,
  32.               (uchar *)w2->pos,w2->len,0);
  33. }
  34.  
  35. int ft_init_stopwords(const char **sws)
  36. {
  37.   FT_STOPWORD sw;
  38.  
  39.  
  40.   if(!stopwords3)
  41.   {
  42.     if(!(stopwords3=(TREE *)my_malloc(sizeof(TREE),MYF(0)))) return -1;
  43.     init_tree(stopwords3,0,sizeof(FT_STOPWORD),(qsort_cmp)&FT_STOPWORD_cmp,0,
  44.           NULL);
  45.   }
  46.  
  47.   if(!sws) return 0;
  48.  
  49.   for(;*sws;sws++)
  50.   {
  51.     if( (sw.len= (uint) strlen(sw.pos=*sws)) < MIN_WORD_LEN) continue;
  52.     if(!tree_insert(stopwords3, &sw, 0))
  53.     {
  54.       delete_tree(stopwords3); /* purecov: inspected */
  55.       return -1; /* purecov: inspected */
  56.     }
  57.   }
  58.   return 0;
  59. }
  60.  
  61. int is_stopword(char *word, uint len)
  62. {
  63.   FT_STOPWORD sw;
  64.   sw.pos=word;
  65.   sw.len=len;
  66.   return tree_search(stopwords3,&sw) != NULL;
  67. }
  68.  
  69.  
  70. void ft_free_stopwords()
  71. {
  72.   if (stopwords3)
  73.   {
  74.     delete_tree(stopwords3); /* purecov: inspected */    
  75.     my_free((char*) stopwords3,MYF(0));
  76.     stopwords3=0;
  77.   }
  78. }
  79.