Page 1 of 1

How to count the number of hits in each abstract

Posted: Mon May 13, 2024 11:18 pm
by rjshelq77
Hi,

I've recently set up Webinator 27 and am using result profile 2. I would like to display a count of the number of hits which have been found each abstract. That is, I want to display the number of highlighted words which would appear in the document preview.

Any clues about how to get the count of the number of hits in each abstract, will be greatly appreciated. (the Webinator 27 search script is bewilderingly different than my old version 6.1)

Just to further clarify what I'm after, here's a snippet of my old search script, with my alterations to the old original webinator 6.1 script surrounded by comments with the initials RJS. The result that I'm after is called $dnumhits in this snippet:

<!-- ============================== -->
<!-- set up the abstract -->
<switch $SSc_abstractstyle>
<case desc>
<$dabstract=$Description>
<case smart>
<abstract $Body $SSc_abstractlen smart><$dabstract=$ret>
<case dumb>
<abstract $Body $SSc_abstractlen dumb><$dabstract=$ret>
<default><!--<case query>-->
<strfmt $qsrchfmt $txtquery>

<!-- RJS added -->
<$cleanQuery=$ret>
<!-- RJS end addition -->

<abstract $Body $SSc_abstractlen smart $ret><$dabstract=$ret>

<!-- RJS added dnumhits to count the number of hits in the abstract -->
<strfmt "%mbs" $cleanQuery $Body>
<rex row "<b>" $ret></rex>
<$dnumhits=$loop>
<!-- RJS end addition -->

</switch>

Re: How to count the number of hits in each abstract

Posted: Tue May 14, 2024 10:42 am
by John
The code now selects the Abstract directly from the database, and you can do the same with dnum.

You should see code like:

Code: Select all

   <$resultVars = $resultVars "Abstract">
   <makeAbstractSqlExpression>
   <$resultVarExps = $resultVarExps $ret>
that selects the Abstract.

After that you would want something like:

Code: Select all

<$resultVars = $resultVars "dnumhits">
<strfmt $qsrchfmt $txtquery>
<queryfixup var=$ret>
<$cleanMMQuery=$ret>
<$resultVarExps = $resultVarsExps "mminfo ($$cleanMMQuery,Body, 0,0, 6) - '203 hits: '">
I haven't actually tested the code in the script, but the SQL expression works, and should return the dnumhits variable.

Re: How to count the number of hits in each abstract

Posted: Wed May 15, 2024 12:17 am
by rjshelq77
Thank you for your kind reply John, but perhaps I am too dense to figure out how to use the clues which you have provided.

As a starting point, I put the code which you suggested immediately after the lines you said to search for, and the vortex log says:

/webinator/search_rjs2:8687: Field `dnumhits' non-existent
/webinator/search_rjs2:8687: Field non-existent or type error in `dnumhits'
/webinator/search_rjs2:8687: SQLExecute() failed with -1: An error occurred in the function execntexis

Re: How to count the number of hits in each abstract

Posted: Wed May 15, 2024 2:12 pm
by John
I had a type in this line:

Code: Select all

<$resultVarExps = $resultVarsExps "mminfo ($$cleanMMQuery,Body, 0,0, 6) - '203 hits: '">
both variables should have been the same:

Code: Select all

<$resultVarExps = $resultVarExps "mminfo ($$cleanMMQuery,Body, 0,0, 6) - '203 hits: '">

Re: How to count the number of hits in each abstract

Posted: Wed May 22, 2024 12:09 am
by rjshelq77
Thank you for your kind reply. That correction solved the error message problem, but I can't figure out how to use the result. I want to include the number of hits for each abstract immediately above each abstract on the results page.

With Webinator 6, in the section <A NAME=result2>, the line above each abstract included my variable $dnumhits in this manner:

<TD VALIGN+TOP WIDTH="99%">
<result_title>&nbsp;(<result_docsize>)&nbsp;&nbsp;$dnumhits highlights in document

I tried simply changing $dnumhits to <dnumhits> to work with your suggested code, but it was empty.

Re: How to count the number of hits in each abstract

Posted: Fri May 24, 2024 11:44 am
by John
You shouldn't have needed to make that change. Adding dnumhits to resultVars should have put the result into $dnumhits.

Re: How to count the number of hits in each abstract

Posted: Fri May 24, 2024 1:43 pm
by rjshelq77
As you suggested, I added the code:

<$resultVars = $resultVars "dnumhits">
<strfmt $qsrchfmt $txtquery>
<queryfixup var=$ret>
<$cleanMMQuery=$ret>
<$resultVarExps = $resultVarExps "mminfo ($$cleanMMQuery,Body, 0,0, 6) - '203 hits: '">

which is mmediately after the:

<$resultVars = $resultVars "Abstract">

But when I use $dnumhits in the results page, the variable is always 1 for every abstract, regardless of the actual number of highlighted terms.

Re: How to count the number of hits in each abstract

Posted: Mon May 27, 2024 10:15 am
by John
There are a few nuances to how a hit is defined. The following code should work for you, it adds one line after the queryfixup so that every occurrence of every term in the search will count as a hit:

Code: Select all

<$resultVars = $resultVars "dnumhits">
<strfmt $qsrchfmt $txtquery>
<queryfixup var=$ret>
<strfmt "%s @0 w/." $ret>
<$cleanMMQuery=$ret>
<$resultVarExps = $resultVarExps "mminfo ($$cleanMMQuery,Body, 0,0, 6) - '203 hits: '">

Re: How to count the number of hits in each abstract

Posted: Mon May 27, 2024 1:33 pm
by rjshelq77
That's getting closer! Thank you John!

Unfortunately, that gives only one number, which is not the actual number of hits in each individual abstract, but appears to be the total number of hits which were found in the first abstract, and then that same number is repeated for each subsequent abstract.

My goal is to be able to show how many highlighted hits are in each abstract.

Re: How to count the number of hits in each abstract

Posted: Tue May 28, 2024 8:24 am
by John
Most likely

Code: Select all

$dnumhits
has all the results in it, but you are only displaying the first one. You would need to make sure you are iterating over the list similar to the other display variables.