Browse Source

Allow multiple ValuePatternQueries

Johannes Hofmann 7 years ago
parent
commit
3a96a3c2eb
2 changed files with 22 additions and 7 deletions
  1. 2
    0
      src/args.rs
  2. 20
    7
      src/config.rs

+ 2
- 0
src/args.rs View File

32
             .short("s")
32
             .short("s")
33
             .long("search")
33
             .long("search")
34
             .value_name("PATTERN")
34
             .value_name("PATTERN")
35
+            .number_of_values(1)
36
+            .multiple(true)
35
             .help("Search for places which match the given pattern")
37
             .help("Search for places which match the given pattern")
36
             .takes_value(true))
38
             .takes_value(true))
37
         .arg(Arg::with_name("keyval")
39
         .arg(Arg::with_name("keyval")

+ 20
- 7
src/config.rs View File

28
     tile_cache_dir: PathBuf,
28
     tile_cache_dir: PathBuf,
29
     sources: Vec<(String, TileSource)>,
29
     sources: Vec<(String, TileSource)>,
30
     pbf_path: Option<PathBuf>,
30
     pbf_path: Option<PathBuf>,
31
-    search_pattern: Option<String>,
31
+    search_patterns: Vec<String>,
32
     keyval: Vec<(String, String)>,
32
     keyval: Vec<(String, String)>,
33
     keyvalregex: Vec<(String, String)>,
33
     keyvalregex: Vec<(String, String)>,
34
     fps: f64,
34
     fps: f64,
68
     }
68
     }
69
 
69
 
70
     fn merge_arg_matches<'a>(&mut self, matches: &clap::ArgMatches<'a>) {
70
     fn merge_arg_matches<'a>(&mut self, matches: &clap::ArgMatches<'a>) {
71
-        self.search_pattern = matches.value_of("search").map(|s| s.to_string());
71
+        self.search_patterns = matches.values_of("search").map_or_else(
72
+            || vec![],
73
+            |p| {
74
+                p.map(|s| s.to_string()).collect()
75
+            },
76
+        );
72
 
77
 
73
         self.keyval = matches.values_of("keyval").map_or_else(
78
         self.keyval = matches.values_of("keyval").map_or_else(
74
             || vec![],
79
             || vec![],
261
                         tile_cache_dir,
266
                         tile_cache_dir,
262
                         sources: vec![],
267
                         sources: vec![],
263
                         pbf_path,
268
                         pbf_path,
264
-                        search_pattern: None,
269
+                        search_patterns: vec![],
265
                         keyval: vec![],
270
                         keyval: vec![],
266
                         keyvalregex: vec![],
271
                         keyvalregex: vec![],
267
                         fps,
272
                         fps,
421
         self.pbf_path.as_ref().map(|p| p.as_path())
426
         self.pbf_path.as_ref().map(|p| p.as_path())
422
     }
427
     }
423
 
428
 
424
-    pub fn search_pattern(&self) -> Option<&str> {
425
-        self.search_pattern.as_ref().map(|s| s.as_str())
429
+    pub fn search_patterns(&self) -> &[String] {
430
+        self.search_patterns.as_slice()
426
     }
431
     }
427
 
432
 
428
     pub fn keyval(&self) -> &[(String, String)] {
433
     pub fn keyval(&self) -> &[(String, String)] {
434
     }
439
     }
435
 
440
 
436
     pub fn query_args(&self) -> Option<QueryArgs> {
441
     pub fn query_args(&self) -> Option<QueryArgs> {
437
-        match (&self.search_pattern, self.keyval.first(), self.keyvalregex.first()) {
442
+        match (&self.search_patterns.first(), self.keyval.first(), self.keyvalregex.first()) {
438
             (&Some(ref pattern), None, None) => Some(
443
             (&Some(ref pattern), None, None) => Some(
439
-                QueryArgs::ValuePattern(pattern.to_string())
444
+                if self.search_patterns.len() == 1 {
445
+                    QueryArgs::ValuePattern(pattern.to_string())
446
+                } else {
447
+                    QueryArgs::Intersection(
448
+                        self.search_patterns.iter()
449
+                            .map(|s| QueryArgs::ValuePattern(s.to_string()))
450
+                            .collect()
451
+                    )
452
+                }
440
             ),
453
             ),
441
             (&None, Some(keyval), None) => Some(
454
             (&None, Some(keyval), None) => Some(
442
                 if self.keyval.len() == 1 {
455
                 if self.keyval.len() == 1 {