1 package org.apache.maven.repository.indexing;
\r
4 * Copyright 2005-2006 The Apache Software Foundation.
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
19 import org.apache.maven.artifact.factory.ArtifactFactory;
\r
20 import org.apache.maven.repository.indexing.query.CompoundQuery;
\r
21 import org.apache.maven.repository.indexing.query.Query;
\r
22 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
\r
24 import java.util.ArrayList;
\r
25 import java.util.Iterator;
\r
26 import java.util.List;
\r
29 * @author Maria Odea Ching
\r
31 * This class is for "query everything" search in the repository index.
\r
32 * It creates the Query object that will be passed to the DefaultRepositoryIndexSearcher
\r
33 * for searching through all the fields in the index.
\r
35 public class GeneralRepositoryIndexSearcher
\r
37 private RepositoryIndex index;
\r
39 private ArtifactFactory factory;
\r
46 public GeneralRepositoryIndexSearcher( RepositoryIndex index, ArtifactFactory factory )
\r
49 this.factory = factory;
\r
53 * Method for searching the keyword in all the fields in the index. The index fields will be retrieved
\r
54 * and query objects will be constructed using the optional (OR) CompoundQuery.
\r
58 * @throws RepositoryIndexSearchException
\r
60 public List search( String keyword )
\r
61 throws RepositoryIndexSearchException
\r
63 List qryList = new ArrayList();
\r
64 for ( int i = 0; i < index.FIELDS.length; i++ )
\r
66 Query qry = new SinglePhraseQuery( index.FIELDS[i], keyword );
\r
70 CompoundQuery cQry = new CompoundQuery();
\r
71 for ( Iterator iter = qryList.iterator(); iter.hasNext(); )
\r
73 cQry.or( (Query) iter.next() );
\r
75 RepositoryIndexSearcher searcher = new DefaultRepositoryIndexSearcher( index, factory );
\r
77 return searcher.search( cQry );
\r