1
14
15 package gate.creole.ir;
16
17 import java.util.List;
18
19 import javax.swing.JOptionPane;
20
21 import gate.ProcessingResource;
22 import gate.Resource;
23 import gate.creole.*;
24 import gate.gui.MainFrame;
25
26
27 public class SearchPR extends AbstractProcessingResource
28 implements ProcessingResource{
29
30 private IndexedCorpus corpus = null;
31 private String query = null;
32 private String searcherClassName = null;
33 private QueryResultList resultList = null;
34 private int limit = -1;
35 private List fieldNames = null;
36
37 private Search searcher = null;
38
39
40 public SearchPR(){
41 }
42
43
44 public Resource init() throws ResourceInstantiationException {
45 Resource result = super.init();
46 return result;
47 }
48
49
57 public void reInit() throws ResourceInstantiationException {
58 init();
59 }
60
61
65 public void execute() throws ExecutionException {
66 if ( corpus == null){
67 throw new ExecutionException("Corpus is not initialized");
68 }
69 if ( query == null){
70 throw new ExecutionException("Query is not initialized");
71 }
72 if ( searcher == null){
73 throw new ExecutionException("Searcher is not initialized");
74 }
75
76 try {
77 if (((IndexedCorpus) corpus).getIndexManager() == null){
78 MainFrame.unlockGUI();
79 JOptionPane.showMessageDialog(null, "Corpus is not indexed!\n"
80 +"Please index fisrt this corpus!",
81 "Search Procesing", JOptionPane.WARNING_MESSAGE);
82 return;
83 }
84
85 fireProgressChanged(0);
86 resultList = null;
87 searcher.setCorpus((IndexedCorpus) corpus);
88 resultList = searcher.search(query, limit, fieldNames);
89 fireProcessFinished();
90 }
91
92 catch (SearchException ie) {
93 throw new ExecutionException(ie.getMessage());
94 }
95 catch (IndexException ie) {
96 throw new ExecutionException(ie.getMessage());
97 }
98 }
99
100 public void setCorpus(IndexedCorpus corpus) {
101 this.corpus = corpus;
102 }
103
104 public IndexedCorpus getCorpus() {
105 return this.corpus;
106 }
107
108 public void setQuery(String query) {
109 this.query = query;
110 }
111
112 public String getQuery() {
113 return this.query;
114 }
115
116 public void setSearcherClassName(String name){
117 this.searcherClassName = name;
118 try {
119 searcher = (Search) Class.forName(searcherClassName).newInstance();
120 }
121 catch(Exception e){
122 e.printStackTrace();
123 }
124 }
125
126 public String getSearcherClassName(){
127
128 return this.searcher.getClass().getName();
129 }
130
131 public void setLimit(Integer limit){
132 this.limit = limit.intValue();
133 }
134
135 public Integer getLimit(){
136 return new Integer(this.limit);
137 }
138
139 public void setFieldNames(List fieldNames){
140 this.fieldNames = fieldNames;
141 }
142
143 public List getFieldNames(){
144 return this.fieldNames;
145 }
146
147 public QueryResultList getResult(){
148 return resultList;
149 }
150
151 public void setResult(QueryResultList qr){
152 throw new UnsupportedOperationException();
153 }
154
155 }