I am using MSSQLs built in full-text search to create a search engine for a particular part of a website. I am breaking apart each search term into individual terms and querying the DB against each term. At that time I am taking the results and entering them into an Array so that I can do some manipulation to it. Since I am splitting each keyword entered into the search and querying the DB for that term, multiple results of the same ID are being dumped out by the DB.
In an effort to only display one result, I am trying to test whether or no the array already has that ID in it, and if so skip entering that recordset into a multidimensional array.
I think some of the problem could be the array, but if you could take a look at it and see if any issues pop up or if you think you might have a better process to handle this, then please let me know. Thanks.
Code:'Create an array of each word used in the query string 'PreSearchString removes all words considered NOISE by full-text search 'Noise words can be customized via the SQLSERVER\Config directory query_split = Split(PrepSearchString(query)) 'declare an array to hold the results of the query for each word. Dim arrResults() 'declare variable to hold count of records 'this is used to declare size of array needed RScount = 0 'declare variable to hold position in array to add the records from the database arrPos = 0 'decalare variable to determine if the query has run or not First_run_test = 0 'Loop to perform Query on each search term for x = 0 to uBound(query_split) strSQL = "SELECT * FROM TE_ENHANCE WHERE CONTAINS(ENHANCE_DESCR, 'FORMSOF (INFLECTIONAL, " & query_split(x) & ")')" Set RS = Server.CreateObject("ADODB.Recordset") RS.open strSQL, conn, 3, 3 RScount = RS.RecordCount + RScount 'redeclare the array to handle the results from this query reDim Preserve arrResults(2,RScount) DO WHILE NOT RS.EOF 'Test to see if this is the first time being run 'If it isn't the first time run, then test if the array holds the ID or a previous result or no IF First_run_test <> 0 THEN For s = 0 to uBound(arrResults,2) IF arrResults(0,s) = RS("TE_ENHANCEID") THEN RS.MoveNext ELSE arrResults(0,arrPos) = RS("TE_ENHANCEID") arrResults(1,arrPos) = RS("ENHANCE_DESCR") arrPos = arrPos + 1 RS.MoveNext END IF NEXT 'If this is the first run, then just go ahead and enter the record set into the array ELSE arrResults(0,arrPos) = RS("TE_ENHANCEID") arrResults(1,arrPos) = RS("ENHANCE_DESCR") arrPos = arrPos + 1 RS.MoveNext END IF LOOP RS.close first_run_test = 1 NEXT


Reply With Quote

Bookmarks