Author: cstamas Date: Wed Dec 29 13:46:12 2010 New Revision: 1053635 URL: http://svn.apache.org/viewvc?rev=1053635&view=rev Log: Introduced search expressions, and deprecated methods to promote use of SearchExpressions instead of plain strings.
Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java (with props) maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java (with props) maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java (with props) maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java (with props) maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java (with props) maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java (with props) Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/QueryCreator.java Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java?rev=1053635&r1=1053634&r2=1053635&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java Wed Dec 29 13:46:12 2010 @@ -42,6 +42,7 @@ import org.apache.maven.index.context.In import org.apache.maven.index.context.MergedIndexingContext; import org.apache.maven.index.context.StaticContextMemberProvider; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; +import org.apache.maven.index.expr.SearchExpression; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -449,6 +450,19 @@ public class DefaultNexusIndexer } } + public Query constructQuery( Field field, SearchExpression expression ) + throws IllegalArgumentException + { + try + { + return queryCreator.constructQuery( field, expression ); + } + catch ( ParseException e ) + { + throw new IllegalArgumentException( e ); + } + } + // ---------------------------------------------------------------------------- // Identification // ---------------------------------------------------------------------------- Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java?rev=1053635&r1=1053634&r2=1053635&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java Wed Dec 29 13:46:12 2010 @@ -36,6 +36,8 @@ import org.apache.lucene.util.Version; import org.apache.maven.index.context.NexusAnalyzer; import org.apache.maven.index.creator.JarFileContentsIndexCreator; import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator; +import org.apache.maven.index.expr.SearchExpression; +import org.apache.maven.index.expr.SearchTyped; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -91,6 +93,19 @@ public class DefaultQueryCreator return lastField; } + public Query constructQuery( final Field field, final SearchExpression expression ) + throws ParseException + { + SearchType searchType = SearchType.SCORED; + + if ( expression instanceof SearchTyped ) + { + searchType = ( (SearchTyped) expression ).getSearchType(); + } + + return constructQuery( field, expression.getStringValue(), searchType ); + } + public Query constructQuery( final Field field, final String query, final SearchType type ) throws ParseException { Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java?rev=1053635&r1=1053634&r2=1053635&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java Wed Dec 29 13:46:12 2010 @@ -31,6 +31,7 @@ import org.apache.maven.index.context.Co import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; +import org.apache.maven.index.expr.SearchExpression; import org.apache.maven.index.packer.IndexPacker; import org.apache.maven.index.updater.IndexUpdater; @@ -310,11 +311,22 @@ public interface NexusIndexer * @param query * @param type * @return + * @deprecated Use {...@link #constructQuery(Field, SearchExpression)} instead. */ Query constructQuery( Field field, String query, SearchType type ) throws IllegalArgumentException; - // throws ParseException; + /** + * Helper method to construct Lucene query for given field without need for knowledge (on caller side) HOW is a + * field indexed, and WHAT query is needed to achieve that. + * + * @param field + * @param query + * @param type + * @return + */ + Query constructQuery( Field field, SearchExpression expression ) + throws IllegalArgumentException; // ---------------------------------------------------------------------------- // Identification Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/QueryCreator.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/QueryCreator.java?rev=1053635&r1=1053634&r2=1053635&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/QueryCreator.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/QueryCreator.java Wed Dec 29 13:46:12 2010 @@ -18,10 +18,9 @@ */ package org.apache.maven.index; -import java.util.Collection; - import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.search.Query; +import org.apache.maven.index.expr.SearchExpression; /** * A component the creates Lucene Queries from "human written" queires, but also helps client applications to assemble @@ -52,6 +51,20 @@ public interface QueryCreator * @return * @throws ParseException if query parsing is unsuccesful. */ + Query constructQuery( Field field, SearchExpression expression ) + throws ParseException; + + /** + * Constructs query by parsing the query string, using field as default field. This method should be use to + * construct queries (single term or phrase queries) against <b>single field</b>. + * + * @param field + * @param query + * @param type + * @return + * @throws ParseException if query parsing is unsuccesful. + * @deprecated Use {...@link #constructQuery(Field, SearchExpression)} instead. + */ Query constructQuery( Field field, String query, SearchType type ) throws ParseException; @@ -62,8 +75,7 @@ public interface QueryCreator * @param field * @param query * @return query if successfully parsed, or null. - * @deprecated Use {...@link #constructQuery(Collection, String)} or - * {...@link QueryCreator#constructQuery(IndexerField, String, SearchType)} methods instead! + * @deprecated Use {...@link #constructQuery(Field, SearchExpression)} instead. */ Query constructQuery( String field, String query ); Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +/** + * SearchExpression is a wrapper interface for expressions representable as plain strings to be used within searches. + * + * @author cstamas + */ +public interface SearchExpression +{ + /** + * Returns the expression value as plain java String. + * + * @return + */ + String getStringValue(); +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchExpression.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +import org.apache.maven.index.SearchType; + +/** + * SearchTyped is a interface that describes the wanted search type to be used. + * + * @author cstamas + */ +public interface SearchTyped +{ + SearchType getSearchType(); +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTyped.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +import org.apache.maven.index.SearchType; + +/** + * A search typed implementation of string backed search expression. + * + * @author cstamas + */ +public class SearchTypedStringSearchExpression + extends StringSearchExpression + implements SearchTyped +{ + private final SearchType searchType; + + public SearchTypedStringSearchExpression( final String expression, final SearchType searchType ) + throws IllegalArgumentException + { + super( expression ); + + if ( searchType == null ) + { + throw new IllegalArgumentException( "SearchType cannot be null!" ); + } + + this.searchType = searchType; + } + + public SearchType getSearchType() + { + return searchType; + } +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SearchTypedStringSearchExpression.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +import org.apache.maven.index.SearchType; + +/** + * SourcedSearchExpression is a search expression usually "sourced" or backed from some programmatic source (drop down + * with pre-filled values, values from previous searches, etc), and we already know it is complete, exact value that we + * want to search for. Indexer will do it's best to match exactly the provided string value, no more no less. + * + * @author cstamas + */ +public class SourcedSearchExpression + extends SearchTypedStringSearchExpression +{ + public SourcedSearchExpression( final String expression ) + throws IllegalArgumentException + { + super( expression, SearchType.EXACT ); + } +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/SourcedSearchExpression.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +/** + * A simple string based implementation of SearchExpression that is immutable. + * + * @author cstamas + */ +public class StringSearchExpression + implements SearchExpression +{ + private final String expression; + + public StringSearchExpression( final String expression ) + { + if ( expression == null || expression.trim().length() == 0 ) + { + throw new IllegalArgumentException( "The expression's string cannot be empty!" ); + } + + this.expression = expression; + } + + public String getStringValue() + { + return expression; + } +} \ No newline at end of file Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/StringSearchExpression.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java?rev=1053635&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java Wed Dec 29 13:46:12 2010 @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.index.expr; + +import org.apache.maven.index.SearchType; + +/** + * UserInputSearchExpression is a search expression usually coming from user input (like some UI dialogue, UI element or + * CLI). It will be normalized and tokenized and then a search will happen against it. Search expressions of this type + * will always provide "broader" (scored, not exact) results, since it defaults to prefix searches and assumes + * "non complete" input. + * + * @author cstamas + */ +public class UserInputSearchExpression + extends SearchTypedStringSearchExpression +{ + public UserInputSearchExpression( final String expression ) + throws IllegalArgumentException + { + super( expression, SearchType.SCORED ); + } +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/expr/UserInputSearchExpression.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision