
From grdetil@scrc.umanitoba.ca Fri Mar 17 17:03:24 2000
Date: Fri, 17 Mar 2000 16:43:04 -0600 (CST)
From: Gilles Detillieux <grdetil@scrc.umanitoba.ca>
To: "C.W.J. Beenakker" <beenakkr@lorentz.leidenuniv.nl>
Cc: htdig@htdig.org, quinn@bitwrench.com
Subject: Re: [htdig] Boolean error combining "keywords"  with "words"

According to C.W.J. Beenakker:
> Thank you, Gilles, for your rapid response. I tried the patch
> of htsearch but it doesn't seem to work. Instead of a Boolean
> error the search now dies with an error "Premature end of script headers".
> Anyway, I've worked around the problem by adding the word "anything" as
> a htdig-keyword to all the publications in my database, so that I can
> use a Boolean "AND" without restricting the search. As an added benefit,
> I can now fake a unary "NOT" by entering "anything NOT keyword".
> (See http://www.lorentz.leidenuniv.nl/beenakker )

I really should have tested before posting.  There's a problem in Display.cc
in that it doesn't deal well with highlighting when there's no pattern to
highlight.  Here is the corrected patch, which includes my earlier patch
to addRequiredWords...

Please try out the following patch.  It should prevent the addition of
parentheses to the boolean expression when there are no search words,
to avoid the syntax error.

At the same time, it adds an "any_keywords" attribute which, if set to
true, will "or" together all words in the keywords field, instead of
and'ing them together, so that any one of the keywords will be enough
for a match.  This may not be what you want, but it was something that
Kevin Quinn and I discussed last summer, and I never did get the patch
into the 3.1.x series.  This new patch should solve both problems.


*** htsearch/htsearch.cc.nowords	Tue Feb 15 16:17:13 2000
--- htsearch/htsearch.cc	Fri Mar 17 14:02:54 2000
*************** htsearch(char *wordfile, List &searchWor
*** 660,672 ****
  void
  addRequiredWords(List &searchWords, StringList &requiredWords)
  {
!     searchWords.Insert(new WeightWord("(", -1.0), 0);
!     searchWords.Add(new WeightWord(")", -1.0));
! 
!     for (int i = 0; i < requiredWords.Count(); i++)
      {
  	searchWords.Add(new WeightWord("&", -1.0));
! 	searchWords.Add(new WeightWord(requiredWords[i], 1.0));
      }
  }
  
--- 660,691 ----
  void
  addRequiredWords(List &searchWords, StringList &requiredWords)
  {
!     static int	any_keywords = config.Boolean("any_keywords", 0);
!     if (requiredWords.Count() == 0)
! 	return;
!     if (searchWords.Count() > 0)
      {
+ 	searchWords.Insert(new WeightWord("(", -1.0), 0);
+ 	searchWords.Add(new WeightWord(")", -1.0));
  	searchWords.Add(new WeightWord("&", -1.0));
!     }
!     if (requiredWords.Count() == 1)
!     {
! 	searchWords.Add(new WeightWord(requiredWords[0], 1.0));
!     }
!     else
!     {
! 	searchWords.Add(new WeightWord("(", -1.0));
! 	searchWords.Add(new WeightWord(requiredWords[0], 1.0));
! 	for (int i = 1; i < requiredWords.Count(); i++)
! 	{
! 	    if (any_keywords)
! 		searchWords.Add(new WeightWord("|", -1.0));
! 	    else
! 		searchWords.Add(new WeightWord("&", -1.0));
! 	    searchWords.Add(new WeightWord(requiredWords[i], 1.0));
! 	}
! 	searchWords.Add(new WeightWord(")", -1.0));
      }
  }
  
*** htsearch/Display.cc.noword	Thu Feb 17 10:43:28 2000
--- htsearch/Display.cc	Fri Mar 17 16:33:09 2000
*************** Display::excerpt(DocumentRef *ref, Strin
*** 1129,1135 ****
      // If previous conditions are false and "excerpt_show_top" is set to true
      // it shows the whole head. Else, it acts as default.
  
!     if (config.Boolean("excerpt_show_top", 0) || use_meta_description)
        first = 0;
      else
        first = allWordsPattern->FindFirstWord(head, which, length);
--- 1129,1136 ----
      // If previous conditions are false and "excerpt_show_top" is set to true
      // it shows the whole head. Else, it acts as default.
  
!     if (config.Boolean("excerpt_show_top", 0) || use_meta_description ||
! 		!allWordsPattern->hasPattern())
        first = 0;
      else
        first = allWordsPattern->FindFirstWord(head, which, length);
*************** Display::hilight(char *str, String urlan
*** 1206,1212 ****
      int			first = 1;
  
      result = 0;
!     while ((pos = allWordsPattern->FindFirstWord(str, which, length)) >= 0)
      {
  	result.append(str, pos);
  	ww = (WeightWord *) (*searchWords)[which];
--- 1207,1214 ----
      int			first = 1;
  
      result = 0;
!     while (allWordsPattern->hasPattern() &&
! 	   (pos = allWordsPattern->FindFirstWord(str, which, length)) >= 0)
      {
  	result.append(str, pos);
  	ww = (WeightWord *) (*searchWords)[which];

-- 
Gilles R. Detillieux              E-mail: <grdetil@scrc.umanitoba.ca>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930

------------------------------------
To unsubscribe from the htdig mailing list, send a message to
htdig-unsubscribe@htdig.org
You will receive a message to confirm this.

