Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.workbench.search / src / org / simantics / workbench / search / SearchEngine.java
1 package org.simantics.workbench.search;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.scl.runtime.function.Function5;
10
11 public class SearchEngine {
12
13         private String id;
14         private String name;
15         private Function5<IProgressMonitor, ReadGraph, Resource, SearchQuery, Integer, SearchResult> searchFunction;
16         private Set<SearchParam> supportedParams = new HashSet<>();
17         private boolean enabledByDefault;
18         
19         public SearchEngine(String id, Function5<IProgressMonitor, ReadGraph, Resource, SearchQuery, Integer, SearchResult> searchFunction, boolean enabledByDefault) {
20                 this(id, id, searchFunction, enabledByDefault);
21         }
22         
23         public SearchEngine(String id, String name, Function5<IProgressMonitor, ReadGraph, Resource, SearchQuery, Integer, SearchResult> searchFunction, boolean enabledByDefault) {
24                 this.id = id;
25                 this.name = name;
26                 this.searchFunction = searchFunction;
27                 this.enabledByDefault = enabledByDefault;
28         }
29         
30         public String getId() {
31                 return id;
32         }
33         
34         public String getName() {
35                 return name;
36         }
37         
38         public Function5<IProgressMonitor, ReadGraph, Resource, SearchQuery, Integer, SearchResult> getSearchFunction() {
39                 return searchFunction;
40         }
41
42         public boolean isEnabledByDefault() {
43                 return enabledByDefault;
44         }
45
46         @Override
47         public int hashCode() {
48                 return id.hashCode();
49         }
50
51         public void addSupportedParam(String name) {
52                 addSupportedParam(name, name);
53         }
54         
55         public void addSupportedParam(String name, String label) {
56                 this.supportedParams.add(new SearchParam(name, label));
57         }
58         
59         public Set<SearchParam> getSupportedParams() {
60                 return supportedParams;
61         }
62         
63         @Override
64         public boolean equals(Object obj) {
65                 if (obj == null)
66                         return false;
67                 if (obj.getClass() != getClass())
68                         return false;
69                 SearchEngine other = (SearchEngine)obj;
70                 return id.equals(other.id);
71         }
72         
73         @Override
74         public String toString() {
75                 return name;
76         }
77 }