Friday, September 27, 2024

Searching

In the past few months, I've often felt the need for the ability to search my blog database looking for a word in a blog's title. This was very simple to program, although I had problems with quotation marks. The key line to this is split into two: first, the clause '[and] 'entries.name like :p6' is added to the query, then the value of the parameter :p6 is defined as parambyname ('p6').asstring:= '%' + edTitle.Text + '%'; I've done this before in at least one other program, so I knew where to look when I became muddled.

A more intriguing functionality would be the possibility of searching the text of the various blogs for some phrase. At first I was very wary of this as I suspected that it would be very difficult. First of all, there's the population to be considered (i.e. which blogs to search); I didn't want every search to be over the entire database, so I hit upon a scheme by which the results of a blog search (by date, tag, number and now title) would serve as the search population. Then I realised that the search would be very easy, using the built-in function pos that returns the position of a sub-string within a larger string. The sub-string is the search string, and the larger string is the text of each blog. If a match were found - I don't care where - then the blog number would be entered into a new instance of the temp table and eventually the same ShowEntries form would be displayed, showing those blogs whose text contains the search string.

Coding this turned out to be more simple - or at least, quicker - than coding the 'find title' code. I was concerned about the time it would take to run such a query so initially I worked on a population consisting only of two blogs. This was very fast. I then ran a query looking for the word 'guitar' on all the blogs of this month; the first few queries returned were obviously concerned with guitars, but where was the connection between 'Is this the government that we deserve?' 1 and guitars? It took me several minutes to realise that the search had found the target word in the 'This day in history' section! This convinced me that the code 'knew what it was doing' and that I could rely on it.

As it happens, a few days earlier I had been going through older blogs and came across the phrase 'Following the recent entry about Gillian McPherson'; unfortunately this hadn't been linked so I didn't know when 'the recent entry' was. I ran a new query on all the blogs in the database (1826), although had I been a bit more discerning then I would have noticed that there was no point in including blogs written after that specific blog. I barely had time to say 'Jack Robinson' when the results popped up. That was fast!

I've written before about ideas migrating from the OP's "ERP" management program to the blog manager program and vice versa. I considered what I could do with this new capability of searching text. One possibility is adding it to the module that tracks calls with customers. Then I remembered that we have often felt the need for searching text in the documentation program (I just used the 'search title' functionality to find these blogs), so I set about adding it to this program.

As opposed to the blog manager, it took me a long time to get this working in DOCU. There were two problems that exist with this program that don't exist in the blog manager: the first was table structures (I was searching on a wrong parameter which is why many early tests failed), but more importantly, the text is saved not as text but as rich text, so this had to be decoded before the search worked. Eventually I found the correct sequence of commands and now we have full text search there. 

I've just remembered a third problem that held me up for a long time: even though I had added a new button that would execute the full text search, every single time the 'by title' search was executed. Eventually I found what the problem was: the edit box in which one wrote the search phrase had an OnExit handler that called the 'by title' search, so this bypassed the new functionality.

All three of these problems stem from my unfamiliarity with the code; I haven't looked at the source for a couple of years. I still would have had to convert rich text to standard text, but it wouldn't have taken me so long to realise why the searches weren't working.

The dimming hack won't work in DOCU because there isn't really a main window in the sense of the blog manager. This program is not MDI but is an attempt at writing something similar without MDI; as a result, windows can be opened all over the screen, and z-order is maintained by using the 'sendtoback' and 'sendtofront' methods.

Internal links
[1] 1822
[2] 518



This day in history:

Blog #Date TitleTags
126027/09/2019Blood test resultsHealth
153127/09/2022More statistical analysisProgramming, Statistics, Psychology

No comments: