API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.search.simpleindexer. JOTRawSearchResult View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

/*
------------------------------------
JavaOnTracks          Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
 */
package net.jot.search.simpleindexer;

import java.util.Hashtable;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * The "raw" search results for one keyword esrach results.
 * @author tcolar
 */
public class JOTRawSearchResult {
    static final Pattern resultPattern=Pattern.compile(" (\\d+):(\\d+)");
    // whichever keyword those results are for.
    private String keyword=null;
    private Hashtable results=new Hashtable();
    
    /**
     * Return an array of Integer[], containing the line number(s) where the keyword was found in the specified file(identified by it's id)
     * If a keyword is on the same line twice, that line number will be in the array twice
     * @param id
     * @return
     */
    public Integer[] getResultsForId(String id)
    {
        if(results.get(id) == null)
            return new Integer[0];
        return (Integer[])((Vector)results.get(id)).toArray(new Integer[0]);
    }
    
    /**
     * Get the list of macthing id's (default: filepath), or whatever the uniqueId was when you indexed the file
     * @return
     */
    public String[] getMatchingIds()
    {
        return (String[])results.keySet().toArray(new String[0]);
    }

    public void setKeyword(String keyword)
    {
        this.keyword = keyword;
    }

    /**
     * return the keyword those results are for.
     * @return
     */
    public String getKeyword()
    {
        return keyword;
    }
    
    /**
     * constructor, called from searchengine
     * indexLine: the keyword line from the index file for the keyword
     */
    protected JOTRawSearchResult(JOTIndexHandler handler,String keyword,  String indexLine)
    {
        this.keyword=keyword;
        Matcher m=resultPattern.matcher(indexLine);
        while(m.find())
        {
            String id=m.group(1);
            String line=m.group(2);
            String key=handler.getMasterKeyById(id);
            Vector v=new Vector();
            if(results.containsKey(key))
            {
                v=(Vector)results.get(key);
            }
            v.add(new Integer(line));
            results.put(key,v);
        }
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar