How to count the number of hits in each abstract

Post Reply
rjshelq77
Posts: 9
Joined: Mon May 13, 2024 10:52 pm

How to count the number of hits in each abstract

Post 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>
User avatar
John
Site Admin
Posts: 2605
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

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

Post 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.
John Turnbull
Thunderstone Software
rjshelq77
Posts: 9
Joined: Mon May 13, 2024 10:52 pm

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

Post 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
User avatar
John
Site Admin
Posts: 2605
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

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

Post 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: '">
John Turnbull
Thunderstone Software
rjshelq77
Posts: 9
Joined: Mon May 13, 2024 10:52 pm

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

Post 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.
User avatar
John
Site Admin
Posts: 2605
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

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

Post by John »

You shouldn't have needed to make that change. Adding dnumhits to resultVars should have put the result into $dnumhits.
John Turnbull
Thunderstone Software
rjshelq77
Posts: 9
Joined: Mon May 13, 2024 10:52 pm

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

Post 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.
User avatar
John
Site Admin
Posts: 2605
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

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

Post 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: '">
John Turnbull
Thunderstone Software
rjshelq77
Posts: 9
Joined: Mon May 13, 2024 10:52 pm

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

Post 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.
User avatar
John
Site Admin
Posts: 2605
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

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

Post 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.
John Turnbull
Thunderstone Software
Post Reply