NetTalk Central

Author Topic: Search question  (Read 3747 times)

wasatchconsulting

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
    • Email
Search question
« on: August 29, 2022, 07:31:58 PM »
I have a client that would like to change the behavior of the search field. At the moment I have it on "Search" so that they can enter multiple words. You can add the "+" to the beginning of a word to require that the word must appear in the resulting records. They would like to have the "+" added by default. Is there any method to do this?

Ken Watts

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Search question
« Reply #1 on: August 29, 2022, 11:23:04 PM »
probably your easiest way to do this is to "adjust" the filter string directly, before it's used by MakeFilter.
So embed into WebHandler, MakeFilter method.

NetWebServerWorkerBase.MakeFilter   Procedure(String p_Filter,String p_Sub, String p_Str,Long p_Type,Long p_Case=0)
str  stringtheory
  code
  if p_Type = net:search
    str.SetValue(p_filter)
    ! edit the filter so every term has a + or - before it.
    return parent.MakeFilter(str.getvalue(),p_sub,p_Str,p_Type,p_Case)
  end
  return parent.MakeFilter(p_Filter,p_sub,p_Str,p_Type,p_Case)


wasatchconsulting

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
    • Email
Re: Search question
« Reply #2 on: August 30, 2022, 12:55:37 PM »
Bruce,

Thanks for the reply. I added code to the MakeFilter procedure in the WebHandler as follows:

p_web.MakeFilter PROCEDURE(String p_Filter,String p_Sub,String p_Str,Long p_Type,Long p_Case=0)

ReturnValue          ANY

! Start of "NetTalk Method Data Section"
! [Priority 5000]
strf                    StringTheory
i                       Long
! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 2500]
        if p_type = Net:Search
            strf.SetValue(p_Filter)
            IF strf.CountWords() > 1
                strf.Split(' ','"')
                LOOP i = 2 to strf.Records()
                    IF CLIP(UPPER(strf.GetLine(i))) = 'AND' OR CLIP(UPPER(strf.GetLine(i))) = 'OR' OR CLIP(UPPER(strf.GetLine(i))) = '&'
                        strf.DeleteLine(i)
                    ELSE
                        CASE SUB(strf.GetLine(i),1,1)
                        OF '-'
                        OF '+'
                        OF '|'
                            strf.SetLine(i,SUB(strf.GetLine(i),2,len(strf.GetLine(i)) -1))
                        ELSE
                            strf.SetLine(i, '+' & strf.GetLine(i))
                        END
                    END
                END
                strf.Join(' ')
                p_Filter = strf.GetValue()
                ReturnValue = parent.MakeFilter(p_Filter,p_sub,p_Str,p_Type,p_Case)             
            END
        END
  ! Parent Call
  ReturnValue = PARENT.MakeFilter(p_Filter,p_Sub,p_Str,p_Type,p_Case)
  ! [Priority 7500]
 
  ! End of "NetTalk Method Executable Code Section"
  RETURN ReturnValue


This is not having any effect. When I enter two words, I am still needing to add the "+" key to get the desired result.
When I placed a stop right before "strf.SetValue(p_Filter)" to display the "p_Filter" field it is showing nothing there.

Do I have this in the right place?

Thanks for your help
Ken Watts

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Search question
« Reply #3 on: August 30, 2022, 10:31:14 PM »
>> p_Filter = strf.GetValue()
you can't do this. p_Filter is not long enough for your changed string.
Hence why I suggested

    Return parent.MakeFilter( strf.GetValue(),p_sub,p_Str,p_Type,p_Case)         

The Return is necessary here because otherwise it just flows down into the parent call.

your editing code also looks wrong in all kinds of ways. I'm not sure why you are deleting terms. And deleting terms will change line numbers.
But you shouldn't be deleting terms in the first place

I recommend you inspect  strf.GetValue() after your Join
strf.trace()
and refine your code until it does what you want.

Cheers
Bruce

wasatchconsulting

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
    • Email
Re: Search question
« Reply #4 on: August 31, 2022, 08:50:02 AM »
Bruce,

I have trim the code down to

if p_type = Net:Search
        strf.Trace('Start of search')
        strf.SetValue(p_Filter)
        strf.Trace()
        IF strf.CountWords() > 1
            strf.Trace('More that 1 word')
            strf.Split(' ','"')
            strf.Trace()
            LOOP i = 2 to strf.Records()
                strf.SetLine(i, '+' & strf.GetLine(i))
            END
            strf.Join(' ')
            strf.Trace()
            ReturnValue = parent.MakeFilter(strf.GetValue(),p_sub,p_Str,p_Type,p_Case)             
        END
        strf.Trace('End of search')
    END

I placed the traces and debug is returning

[st] Start of Search
[st]
[st] End of Search

So the "p_Filter" is coming back is blank.

Ken Watts

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Search question
« Reply #5 on: September 04, 2022, 10:32:18 PM »
Hi Ken,

So you're saying your code to change the filter is wrong?

I guess you need to add more trace statements to see where your expectation of what is happening is different from what is actually happening.
Starting with viewing the p_filter parameter on input, then examining what you are doing to it after that.

Like what is CountWords returning, why are you only looping from the second record, and so on.

I feel like this bit of code is within your grasp, it's just a case of working through it slowly to see what you are doing, and get to the result you are looking for.

hint - given that you don't see strf.Trace('More that 1 word') in your output, would suggest that countWords is not returning what you think.

Cheers
Bruce