codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Text Search  Cooler King at 15:41 on Thursday, February 26, 2004
 

Hi all,

I want to able to search through a text file and display the lines if they have a match. I've got it to work with the following code below only matches exactly what search for, if i search for say "Bloggs" it matches it but if i search for "Bloggs Marketing" it doesn't match because the actual line in the text file looks like this:

"Joe Bloggs Department of Marketing"

So heres my question how do i get it to search the whole string and return unexact matches (e.g. "Bloggs Marketing")

Thanks in advance.

Heres my code:

<% option explicit %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Telephone Directory - Results Page</title>
<link href="/forum/domcompat.css" rel="stylesheet" type="text/css">
</head>

<body>
<div align="center">
<form>
<div>
<table>
<tr class="pdcellcolour2">
<td colspan="2"><img src="/forum/directorytitle.jpg"></td>
</tr>
<tr class="pdcellcolour2">
<td>
<br><strong>Search Results for <%=Request ("SearchField")%></strong><br><br>

<%

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.fileSystemObject")

Dim strSearchField
strSearchField = Request("SearchField")

Dim objTextStream
Dim strFileContents
Dim objLine
Dim strLine
Dim strMatch
const strFileName = "/forum/ehtdocsDirectorydirectory.txt"
const fsoForReading = 1


Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)


Function printLine(strLine)
response.write strLine & "<br>"
end Function

While Not objTextStream.AtEndOfStream
objLine = objTextStream.ReadLine
if instr(objLine,uCase(strSearchField)) > 0 Then
printLine(objLine)
End if
WEnd


objTextStream.Close
Set objTextStream = Nothing

Set objFSO = Nothing
%>
<br><br></td>
</tr>
</table>
</div>
</form>
</body>
</html>




  Advanced text searching and pattern matching  Troy Wolf at 13:36 on Friday, February 27, 2004
 

I'd be interested in reading about advanced text searching and pattern matching techniques, too. Maybe somebody has some advanced experience and would take the time to post.

Depending on your platform and exact needs there are other tools you can use such as Microsoft's built in Text Indexing, but I'm not sure how to use that.

If you are dealing with a text website that has been online for more than 30 days and is indexed by Google, some people just use Google's search to provide search to their own site. For example, click this link:

http://www.google.com/search?q=Troy+Wolf+site%3Acodetoad.com

This will bring back a list of pages that include the words "Troy" and "Wolf" and only those matching pages within the the codetoad.com website. Specify which site by just adding " site:codetoad.com" to your google query string.

Back to your task....the first solution that comes to mind is you break your search string into individual words. This can be done easily with VBScript using the Split() function. It can be used to split a string at each space putting the elements into an array. Now, as you examine each line, loop through your array individually checking for a match to each keyword. Only call the line a match if it matches all your keywords -- or whatever you want to do. :)




<Added>

By the way, the Google technique to search keywords only in a specific site is so good, I normally use it INSTEAD of a website's own search tool. For example, recently I've been doing a lot of PHP coding. I'm new to PHP, so I have to reference the manual at www.php.net a lot. For some reason, I have terrible luck using the search that is part of php.net's site. So I just use Google to search only PHP.net. It works fantastic.
Troy Wolf: site expert
SnippetEdit Website Editor









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  New LucidWorks certified distribution for Solr
•  Re: submit button on html form
•  Re: FREE TV on your PC!
•  Re: How to edit a PCL file
•  Re: How to open a pop up without Titlebar?
•  Re: Testing if object exists in IE
•  Re: windows service - web service - com
•  Re: Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  Re: Using ASP to write RTF


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010