Class SearchCompiler
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.search.SearchCompiler
-
public class SearchCompiler extends Object
Implements a google-like search.
Grammar:expression = fact | expression fact expression fact fact = ( expression ) -fact term? term=term term:term term
- Since:
- 12656 (moved from actions.search package)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchCompiler.AbstractBinaryMatch
A binary search operator which may take data parameters.static class
SearchCompiler.Always
Matches every OsmPrimitive.static class
SearchCompiler.And
Matches if both left and right expressions match.private static class
SearchCompiler.Any
Match a string in any tags (key or value), with optional regex and case insensitivity.private static class
SearchCompiler.AreaSize
Matches if the size of the area is within the given rangestatic interface
SearchCompiler.BinaryMatchFactory
static class
SearchCompiler.BooleanMatch
Matches if the value of the corresponding key is ''yes'', ''true'', ''1'' or ''on''.private static class
SearchCompiler.ChangesetId
Matches objects with a changeset ID in the given range.static class
SearchCompiler.Child
Matches objects if they are children of the expressionprivate static class
SearchCompiler.Closed
Matches ways which are closed (i.e.static class
SearchCompiler.CoreSimpleMatchFactory
static class
SearchCompiler.CoreUnaryMatchFactory
private static class
SearchCompiler.Deleted
Matches all objects that have been deletedstatic class
SearchCompiler.ExactKeyValue
Matches objects with the exact given key-value pair.static class
SearchCompiler.ExactType
private static class
SearchCompiler.HasRole
Matches relations with a member of the given roleprivate static class
SearchCompiler.Id
Matches objects with ID in the given range.static class
SearchCompiler.InArea
Matches objects within the given bounds.private static class
SearchCompiler.Incomplete
Match objects that are incomplete, where only id and type are known.static class
SearchCompiler.InDataSourceArea
Matches objects within source area ("downloaded area").static class
SearchCompiler.KeyValue
Matches objects with the given key-value pair.private static class
SearchCompiler.MapCSSMatch
static class
SearchCompiler.Match
Base class for all search criteria.private static interface
SearchCompiler.MatchFactory
Classes implementing this interface can provide Match operators.static interface
SearchCompiler.MatchSupplier
Classes implementing this interface can provide Match instances themselves and do not rely oncompile(String)
.private static class
SearchCompiler.MemberCountRange
private static class
SearchCompiler.Modified
Matches all objects that have been modified, created, or undeletedstatic class
SearchCompiler.Never
Never matches any OsmPrimitive.private static class
SearchCompiler.New
Matches objects that are new (i.e.private static class
SearchCompiler.NodeCountRange
Matches ways with a number of nodes in given rangestatic class
SearchCompiler.Not
Inverts the match.static class
SearchCompiler.NotOutsideDataSourceArea
Matches objects which are not outside the source area ("downloaded area").private static class
SearchCompiler.Nth
Matches the n-th object of a relation and/or the n-th node of a way.static class
SearchCompiler.Or
Matches if the left OR the right expression match.static class
SearchCompiler.Parent
Matches objects if they are parents of the expressionprivate static class
SearchCompiler.Preset
Matches presets.private static class
SearchCompiler.RangeMatch
Matches objects with properties in a certain range.private static class
SearchCompiler.RoleMatch
Matches objects with the given relation role (i.e.private static class
SearchCompiler.Selected
Matches all objects currently selectedstatic interface
SearchCompiler.SimpleMatchFactory
private static class
SearchCompiler.TagCountRange
Matches objects with a number of tags in given rangestatic class
SearchCompiler.TaggedMatch
private static class
SearchCompiler.TimestampRange
Matches objects with a timestamp in given rangestatic class
SearchCompiler.UnaryMatch
A unary search operator which may take data parameters.static interface
SearchCompiler.UnaryMatchFactory
private static class
SearchCompiler.Untagged
Matches objects that don't have any interesting tags (i.e.static class
SearchCompiler.UserMatch
Matches objects last changed by the given username.static class
SearchCompiler.ValueComparison
private static class
SearchCompiler.Version
Matches objects with a version number in the given range.private static class
SearchCompiler.WayCountRange
Matches objects with the number of referring/contained ways in the given rangeprivate static class
SearchCompiler.WayLength
Matches if the length of a way is within the given rangestatic class
SearchCompiler.Xor
Matches if the left OR the right expression match, but not both.
-
Field Summary
Fields Modifier and Type Field Description private static Map<String,SearchCompiler.BinaryMatchFactory>
binaryMatchFactoryMap
private boolean
caseSensitive
private boolean
regexSearch
private static String
rxErrorMsg
private static String
rxErrorMsgNoPos
private static Map<String,SearchCompiler.SimpleMatchFactory>
simpleMatchFactoryMap
private PushbackTokenizer
tokenizer
private static Map<String,SearchCompiler.UnaryMatchFactory>
unaryMatchFactoryMap
-
Constructor Summary
Constructors Constructor Description SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer)
Constructs a newSearchCompiler
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addMatchFactory(SearchCompiler.MatchFactory factory)
Add (register) MatchFactory with SearchCompilerstatic String
buildSearchStringForTag(String key, String value)
Builds a search string for the given tag.static SearchCompiler.Match
compile(String searchStr)
Compiles the search expression.static SearchCompiler.Match
compile(SearchSetting setting)
Compiles the search expression.(package private) static SearchCompiler.Match
compileMapCSS(String mapCSS)
(package private) static String
escapeStringForSearch(String s)
private SearchCompiler.Match
getValidate(SearchCompiler.UnaryMatchFactory unaryFactory, String key, PushbackTokenizer tokenizer)
SearchCompiler.Match
parse()
Parse search string.private SearchCompiler.Match
parseExpression()
Parse expression.private List<Object>
parseExpressionStep1()
private static SearchCompiler.Match
parseExpressionStep2(List<Object> list)
private SearchCompiler.Match
parseFactor()
Parse next factor (a search operator or search term).private SearchCompiler.Match
parseFactor(String errorMessage)
private static int
regexFlags(boolean caseSensitive)
-
-
-
Field Detail
-
caseSensitive
private final boolean caseSensitive
-
regexSearch
private final boolean regexSearch
-
rxErrorMsg
private static final String rxErrorMsg
-
rxErrorMsgNoPos
private static final String rxErrorMsgNoPos
-
tokenizer
private final PushbackTokenizer tokenizer
-
simpleMatchFactoryMap
private static final Map<String,SearchCompiler.SimpleMatchFactory> simpleMatchFactoryMap
-
unaryMatchFactoryMap
private static final Map<String,SearchCompiler.UnaryMatchFactory> unaryMatchFactoryMap
-
binaryMatchFactoryMap
private static final Map<String,SearchCompiler.BinaryMatchFactory> binaryMatchFactoryMap
-
-
Constructor Detail
-
SearchCompiler
public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer)
Constructs a newSearchCompiler
.- Parameters:
caseSensitive
-true
to perform a case-sensitive searchregexSearch
-true
to perform a regex-based searchtokenizer
- to split the search string into tokens
-
-
Method Detail
-
addMatchFactory
public static void addMatchFactory(SearchCompiler.MatchFactory factory)
Add (register) MatchFactory with SearchCompiler- Parameters:
factory
- match factory
-
compile
public static SearchCompiler.Match compile(String searchStr) throws SearchParseError
Compiles the search expression.- Parameters:
searchStr
- the search expression- Returns:
- a
SearchCompiler.Match
object for the expression - Throws:
SearchParseError
- if an error has been encountered while compiling- See Also:
compile(SearchSetting)
-
compile
public static SearchCompiler.Match compile(SearchSetting setting) throws SearchParseError
Compiles the search expression.- Parameters:
setting
- the settings to use- Returns:
- a
SearchCompiler.Match
object for the expression - Throws:
SearchParseError
- if an error has been encountered while compiling- See Also:
compile(String)
-
compileMapCSS
static SearchCompiler.Match compileMapCSS(String mapCSS) throws SearchParseError
- Throws:
SearchParseError
-
parse
public SearchCompiler.Match parse() throws SearchParseError
Parse search string.- Returns:
- match determined by search string
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseExpression
private SearchCompiler.Match parseExpression() throws SearchParseError
Parse expression.- Returns:
- match determined by parsing expression
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseExpressionStep1
private List<Object> parseExpressionStep1() throws SearchParseError
- Throws:
SearchParseError
-
parseExpressionStep2
private static SearchCompiler.Match parseExpressionStep2(List<Object> list)
-
parseFactor
private SearchCompiler.Match parseFactor() throws SearchParseError
Parse next factor (a search operator or search term).- Returns:
- match determined by parsing factor string
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseFactor
private SearchCompiler.Match parseFactor(String errorMessage) throws SearchParseError
- Throws:
SearchParseError
-
getValidate
private SearchCompiler.Match getValidate(SearchCompiler.UnaryMatchFactory unaryFactory, String key, PushbackTokenizer tokenizer) throws SearchParseError
- Throws:
SearchParseError
-
regexFlags
private static int regexFlags(boolean caseSensitive)
-
escapeStringForSearch
static String escapeStringForSearch(String s)
-
buildSearchStringForTag
public static String buildSearchStringForTag(String key, String value)
Builds a search string for the given tag. If value is empty, the existence of the key is checked.- Parameters:
key
- the tag keyvalue
- the tag value- Returns:
- a search string for the given tag
-
-