1 17 package org.alfresco.repo.search; 18 19 import java.io.Serializable ; 20 import java.util.List ; 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 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 language, 55 String 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 throw new UnsupportedOperationException (); 67 } 68 69 public ResultSet query(SearchParameters searchParameters) 70 { 71 if(searchParameters.getStores().size() != 1) 72 { 73 throw new IllegalStateException ("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 googleLikePattern) throws InvalidNodeRefException 81 { 82 return contains(nodeRef, propertyQName, googleLikePattern, SearchParameters.Operator.OR); 83 } 84 85 public boolean contains(NodeRef nodeRef, QName propertyQName, String 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 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 <NodeRef> selectNodes(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String 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 <Serializable > selectProperties(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks, String 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 |