KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > SearcherComponent


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.search;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.alfresco.service.cmr.repository.InvalidNodeRefException;
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.repository.Path;
25 import org.alfresco.service.cmr.repository.StoreRef;
26 import org.alfresco.service.cmr.repository.XPathException;
27 import org.alfresco.service.cmr.search.QueryParameter;
28 import org.alfresco.service.cmr.search.QueryParameterDefinition;
29 import org.alfresco.service.cmr.search.ResultSet;
30 import org.alfresco.service.cmr.search.SearchParameters;
31 import org.alfresco.service.cmr.search.SearchService;
32 import org.alfresco.service.namespace.NamespacePrefixResolver;
33 import org.alfresco.service.namespace.QName;
34
35 /**
36  * Component API for searching. Delegates to the real {@link org.alfresco.service.cmr.search.SearchService searcher}
37  * from the {@link #indexerAndSearcherFactory}.
38  *
39  * Transactional support is free.
40  *
41  * @author andyh
42  *
43  */

44 public class SearcherComponent extends AbstractSearcherComponent
45 {
46     private IndexerAndSearcher indexerAndSearcherFactory;
47     
48     public void setIndexerAndSearcherFactory(IndexerAndSearcher indexerAndSearcherFactory)
49     {
50         this.indexerAndSearcherFactory = indexerAndSearcherFactory;
51     }
52
53     public ResultSet query(StoreRef store,
54             String JavaDoc language,
55             String JavaDoc query,
56             Path[] queryOptions,
57             QueryParameterDefinition[] queryParameterDefinitions)
58     {
59         SearchService searcher = indexerAndSearcherFactory.getSearcher(store, true);
60         return searcher.query(store, language, query, queryOptions, queryParameterDefinitions);
61     }
62
63     public ResultSet query(StoreRef store, QName queryId, QueryParameter[] queryParameters)
64     {
65         // TODO Auto-generated method stub
66
throw new UnsupportedOperationException JavaDoc();
67     }
68
69     public ResultSet query(SearchParameters searchParameters)
70     {
71         if(searchParameters.getStores().size() != 1)
72         {
73             throw new IllegalStateException JavaDoc("Only one store can be searched at present");
74         }
75         StoreRef storeRef = searchParameters.getStores().get(0);
76         SearchService searcher = indexerAndSearcherFactory.getSearcher(storeRef, !searchParameters.excludeDataInTheCurrentTransaction());
77         return searcher.query(searchParameters);
78     }
79
80     public boolean contains(NodeRef nodeRef, QName propertyQName, String JavaDoc googleLikePattern) throws InvalidNodeRefException
81     {
82         return contains(nodeRef, propertyQName, googleLikePattern, SearchParameters.Operator.OR);
83     }
84     
85     public boolean contains(NodeRef nodeRef, QName propertyQName, String JavaDoc googleLikePattern, SearchParameters.Operator defaultOperator) throws InvalidNodeRefException
86     {
87         SearchService searcher = indexerAndSearcherFactory.getSearcher(nodeRef.getStoreRef(), true);
88         return searcher.contains(nodeRef, propertyQName, googleLikePattern);
89     }
90
91     public boolean like(NodeRef nodeRef, QName propertyQName, String JavaDoc sqlLikePattern, boolean includeFTS) throws InvalidNodeRefException
92     {
93         SearchService searcher = indexerAndSearcherFactory.getSearcher(nodeRef.getStoreRef(), true);
94         return searcher.like(nodeRef, propertyQName, sqlLikePattern, includeFTS);
95     }
96
97     public List JavaDoc<NodeRef> selectNodes(NodeRef contextNodeRef, String JavaDoc xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String JavaDoc language) throws InvalidNodeRefException, XPathException
98     {
99         SearchService searcher = indexerAndSearcherFactory.getSearcher(contextNodeRef.getStoreRef(), true);
100         return searcher.selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language);
101     }
102
103     public List JavaDoc<Serializable JavaDoc> selectProperties(NodeRef contextNodeRef, String JavaDoc xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String JavaDoc language) throws InvalidNodeRefException, XPathException
104     {
105         SearchService searcher = indexerAndSearcherFactory.getSearcher(contextNodeRef.getStoreRef(), true);
106         return searcher.selectProperties(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language);
107     }
108 }
109
Popular Tags