Skip to main content

How to use your own search engine

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Roger Brinkley

dell wrote:
> Roger Brinkley,
> How are you!
> Thank you for your warmhearted and patient direction,thank you very much!
> In the light of your method, I have finished my work. I feel very excited about it.
> The only problem is that I can't find the SearchItem's "begin" and "end" pointer.
> public class SearchItem {
> private URL base;
> private String title;
> private String lang;
> private String filename;
> private double confidence;
> private int begin;
> private int end;
> private Vector concepts;
> }
> This is part of my program
> SearchItem si = new SearchItem(myurl, title,
> Locale.getDefault().toString(),
> filename,
> hits.score(i),
> 0,
> 0,
> new Vector(1));
>
> "concepts" is empty vector. because I don't known the meaning of it.
> the field of "begin" and "end" is 0. because I cannot find the searchitem's begin and end position
>
> I have use the following code.
> the principle of this algorithm is :
> suppose: variable "word" is to be searched.
> firstly, to get the html file's content and save it into the variable "content"
> secondly, to search everyword like "word" in "content" and get the begin and end position of "word".
> thirdly, to pass the begin and end position to searchitem.
>
> public static void addSearchItem(File file,
> String title,
> String locale,
> String filename,
> float score,
> Vector concepts) {
> StringBuffer txt = null;
> try {
> txt = new StringBuffer();
> BufferedReader infile =
> new BufferedReader(
> new FileReader(file));
> String s = null;
> while ( (s = infile.readLine()) != null) {
> txt.append(s);
> }
> infile.close();
> }catch(Exception es){
> es.printStackTrace();
> return;
> }
> String content = txt.toString().toLowerCase();
> if(content == null)
> return;
> int dd = content.indexOf("");
> int index = content.indexOf(word, dd);// word is the searched word.
> int start = 0, end = 0;
> while(index >= 0 && index < content.length()){
> start = index;
> end = start + word.length();
> try {
> SearchItem si = new SearchItem(file.toURL(),
> title,
> locale,
> filename,
> score,
> start,
> end,
> concepts);
> result.add(si);
> }catch(Exception es){}
> index = content.indexOf(word, end);
> }
> }
>
>
> when I do that, I found the "begin" and "end" position of this method isn't the exact "begin" and "end" position of searchitem
> What should I do?

Concepts is a vector of Strings that the match occurred on. Some search
engines have the capability of morphing words (click, clicking, clicked)
or compatible words (car, auto, automobile).

As far as the begin and end are concerned they are tightly tied to the
jeditor pane. They represent the place where the highlighting will
appear. Since your search engine isn't based on the jeditor pane make
them both zero ("0"). That should take care of the problem.

Binky

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.