Class SearchCompiler
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.search.SearchCompiler
-
public class SearchCompiler extends java.lang.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 classSearchCompiler.AbstractBinaryMatchA binary search operator which may take data parameters.static classSearchCompiler.AlwaysMatches every OsmPrimitive.static classSearchCompiler.AndMatches if both left and right expressions match.private static classSearchCompiler.AnyMatch a string in any tags (key or value), with optional regex and case insensitivity.private static classSearchCompiler.AreaSizeMatches if the size of the area is within the given rangestatic interfaceSearchCompiler.BinaryMatchFactoryA factor for gettingSearchCompiler.AbstractBinaryMatchobjectsstatic classSearchCompiler.BooleanMatchMatches if the value of the corresponding key is ''yes'', ''true'', ''1'' or ''on''.private static classSearchCompiler.ChangesetIdMatches objects with a changeset ID in the given range.static classSearchCompiler.ChildMatches objects if they are children of the expressionprivate static classSearchCompiler.ClosedMatches ways which are closed (i.e.static classSearchCompiler.CoreSimpleMatchFactoryThe core factory for "simple"SearchCompiler.Matchobjectsstatic classSearchCompiler.CoreUnaryMatchFactoryThe coreSearchCompiler.UnaryMatchfactoryprivate static classSearchCompiler.DeletedMatches all objects that have been deletedstatic classSearchCompiler.ExactKeyValueMatches objects with the exact given key-value pair.static classSearchCompiler.ExactTypeFilter OsmPrimitives based off of the base primitive typeprivate static classSearchCompiler.HasRoleMatches relations with a member of the given roleprivate static classSearchCompiler.IdMatches objects with ID in the given range.static classSearchCompiler.InAreaMatches objects within the given bounds.private static classSearchCompiler.IncompleteMatch objects that are incomplete, where only id and type are known.static classSearchCompiler.InDataSourceAreaMatches objects within source area ("downloaded area").static classSearchCompiler.KeyValueMatches objects with the given key-value pair.private static classSearchCompiler.MapCSSMatchstatic classSearchCompiler.MatchBase class for all search criteria.private static interfaceSearchCompiler.MatchFactoryClasses implementing this interface can provide Match operators.static interfaceSearchCompiler.MatchSupplierClasses implementing this interface can provide Match instances themselves and do not rely oncompile(String).private static classSearchCompiler.MemberCountRangeprivate static classSearchCompiler.ModifiedMatches all objects that have been modified, created, or undeletedstatic classSearchCompiler.NeverNever matches any OsmPrimitive.private static classSearchCompiler.NewMatches objects that are new (i.e.private static classSearchCompiler.NodeCountRangeMatches ways with a number of nodes in given rangestatic classSearchCompiler.NotInverts the match.static classSearchCompiler.NotOutsideDataSourceAreaMatches objects which are not outside the source area ("downloaded area").private static classSearchCompiler.NthMatches the n-th object of a relation and/or the n-th node of a way.static classSearchCompiler.OrMatches if the left OR the right expression match.static classSearchCompiler.ParentMatches objects if they are parents of the expressionprivate static classSearchCompiler.PresetMatches presets.private static classSearchCompiler.RangeMatchMatches objects with properties in a certain range.private static classSearchCompiler.RoleMatchMatches objects with the given relation role (i.e.private static classSearchCompiler.SelectedMatches all objects currently selectedstatic interfaceSearchCompiler.SimpleMatchFactoryA factory for gettingSearchCompiler.Matchobjectsprivate static classSearchCompiler.TagCountRangeMatches objects with a number of tags in given rangestatic classSearchCompiler.TaggedMatchA common subclass ofSearchCompiler.Matchfor matching against tagsprivate static classSearchCompiler.TimestampRangeMatches objects with a timestamp in given rangestatic classSearchCompiler.UnaryMatchA unary search operator which may take data parameters.static interfaceSearchCompiler.UnaryMatchFactoryA factory for gettingSearchCompiler.UnaryMatchobjectsprivate static classSearchCompiler.UntaggedMatches objects that don't have any interesting tags (i.e.static classSearchCompiler.UserMatchMatches objects last changed by the given username.static classSearchCompiler.ValueComparisonMatch a primitive based off of a value comparison.private static classSearchCompiler.VersionMatches objects with a version number in the given range.private static classSearchCompiler.WayCountRangeMatches objects with the number of referring/contained ways in the given rangeprivate static classSearchCompiler.WayLengthMatches if the length of a way is within the given rangestatic classSearchCompiler.XorMatches if the left OR the right expression match, but not both.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringALL_IN_DOWNLOADED_AREAprivate static java.lang.StringAREA_SIZEprivate static java.util.Map<java.lang.String,SearchCompiler.BinaryMatchFactory>binaryMatchFactoryMapprivate booleancaseSensitiveprivate static java.lang.StringCHANGESETprivate static java.lang.StringCLOSEDprivate static java.lang.StringDELETEDprivate static java.lang.StringIN_DOWNLOADED_AREAprivate static java.lang.StringINCOMPLETEprivate static java.lang.StringMEMBERSprivate static java.lang.StringMODIFIEDprivate static java.lang.StringNODESprivate static java.lang.StringRANGE_OF_NUMBERS_EXPECTEDprivate static java.lang.StringREGEX_ERROR_MESSAGEprivate static java.lang.StringREGEX_ERROR_MESSAGE_NO_POSITIONprivate booleanregexSearchprivate static java.lang.StringSELECTEDprivate static java.util.Map<java.lang.String,SearchCompiler.SimpleMatchFactory>simpleMatchFactoryMapprivate static java.lang.StringTIMESTAMPprivate PushbackTokenizertokenizerprivate static java.util.Map<java.lang.String,SearchCompiler.UnaryMatchFactory>unaryMatchFactoryMapprivate static java.lang.StringUNTAGGEDprivate static java.lang.StringVERSIONprivate static java.lang.StringWAY_LENGTHprivate static java.lang.StringWAYS
-
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 voidaddMatchFactory(SearchCompiler.MatchFactory factory)Add (register) MatchFactory with SearchCompilerstatic java.lang.StringbuildSearchStringForTag(java.lang.String key, java.lang.String value)Builds a search string for the given tag.static SearchCompiler.Matchcompile(java.lang.String searchStr)Compiles the search expression.static SearchCompiler.Matchcompile(SearchSetting setting)Compiles the search expression.(package private) static SearchCompiler.MatchcompileMapCSS(java.lang.String mapCSS)(package private) static java.lang.StringescapeStringForSearch(java.lang.String s)private SearchCompiler.MatchgetValidate(SearchCompiler.UnaryMatchFactory unaryFactory, java.lang.String key, PushbackTokenizer tokenizer)SearchCompiler.Matchparse()Parse search string.private SearchCompiler.MatchparseExpression()Parse expression.private java.util.List<java.lang.Object>parseExpressionStep1()private static SearchCompiler.MatchparseExpressionStep2(java.util.List<java.lang.Object> list)private SearchCompiler.MatchparseFactor()Parse next factor (a search operator or search term).private SearchCompiler.MatchparseFactor(java.lang.String errorMessage)private static intregexFlags(boolean caseSensitive)
-
-
-
Field Detail
-
caseSensitive
private final boolean caseSensitive
-
regexSearch
private final boolean regexSearch
-
REGEX_ERROR_MESSAGE
private static final java.lang.String REGEX_ERROR_MESSAGE
-
REGEX_ERROR_MESSAGE_NO_POSITION
private static final java.lang.String REGEX_ERROR_MESSAGE_NO_POSITION
-
RANGE_OF_NUMBERS_EXPECTED
private static final java.lang.String RANGE_OF_NUMBERS_EXPECTED
-
tokenizer
private final PushbackTokenizer tokenizer
-
simpleMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.SimpleMatchFactory> simpleMatchFactoryMap
-
unaryMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.UnaryMatchFactory> unaryMatchFactoryMap
-
binaryMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.BinaryMatchFactory> binaryMatchFactoryMap
-
AREA_SIZE
private static final java.lang.String AREA_SIZE
- See Also:
- Constant Field Values
-
CHANGESET
private static final java.lang.String CHANGESET
- See Also:
- Constant Field Values
-
CLOSED
private static final java.lang.String CLOSED
- See Also:
- Constant Field Values
-
DELETED
private static final java.lang.String DELETED
- See Also:
- Constant Field Values
-
INCOMPLETE
private static final java.lang.String INCOMPLETE
- See Also:
- Constant Field Values
-
IN_DOWNLOADED_AREA
private static final java.lang.String IN_DOWNLOADED_AREA
- See Also:
- Constant Field Values
-
ALL_IN_DOWNLOADED_AREA
private static final java.lang.String ALL_IN_DOWNLOADED_AREA
- See Also:
- Constant Field Values
-
MEMBERS
private static final java.lang.String MEMBERS
- See Also:
- Constant Field Values
-
MODIFIED
private static final java.lang.String MODIFIED
- See Also:
- Constant Field Values
-
NODES
private static final java.lang.String NODES
- See Also:
- Constant Field Values
-
SELECTED
private static final java.lang.String SELECTED
- See Also:
- Constant Field Values
-
TIMESTAMP
private static final java.lang.String TIMESTAMP
- See Also:
- Constant Field Values
-
UNTAGGED
private static final java.lang.String UNTAGGED
- See Also:
- Constant Field Values
-
VERSION
private static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
WAYS
private static final java.lang.String WAYS
- See Also:
- Constant Field Values
-
WAY_LENGTH
private static final java.lang.String WAY_LENGTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SearchCompiler
public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer)
Constructs a newSearchCompiler.- Parameters:
caseSensitive-trueto perform a case-sensitive searchregexSearch-trueto 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(java.lang.String searchStr) throws SearchParseError
Compiles the search expression.- Parameters:
searchStr- the search expression- Returns:
- a
SearchCompiler.Matchobject 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.Matchobject for the expression - Throws:
SearchParseError- if an error has been encountered while compiling- See Also:
compile(String)
-
compileMapCSS
static SearchCompiler.Match compileMapCSS(java.lang.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 java.util.List<java.lang.Object> parseExpressionStep1() throws SearchParseError
- Throws:
SearchParseError
-
parseExpressionStep2
private static SearchCompiler.Match parseExpressionStep2(java.util.List<java.lang.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(java.lang.String errorMessage) throws SearchParseError
- Throws:
SearchParseError
-
getValidate
private SearchCompiler.Match getValidate(SearchCompiler.UnaryMatchFactory unaryFactory, java.lang.String key, PushbackTokenizer tokenizer) throws SearchParseError
- Throws:
SearchParseError
-
regexFlags
private static int regexFlags(boolean caseSensitive)
-
escapeStringForSearch
static java.lang.String escapeStringForSearch(java.lang.String s)
-
buildSearchStringForTag
public static java.lang.String buildSearchStringForTag(java.lang.String key, java.lang.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
-
-