Skip to content
This repository
Browse code

commit to _design/foo in paths, use regexp to be sure.

  • Loading branch information...
commit 6b73dc6cd9c6fae37fc40714a99cd0ae5f4124a9 1 parent 3d2fb72
authored April 17, 2010
16  README.md
Source Rendered
@@ -92,8 +92,8 @@ Here's an complete example of a design document with couchdb-lucene features:
92 92
 Here are some example URL's for the given design document;
93 93
 
94 94
 <pre>
95  
-http://localhost:5984/database/_fti/foo/by_subject?q=hello
96  
-http://localhost:5984/database/_fti/foo/by_content?q=hello
  95
+http://localhost:5984/database/_fti/_design/foo/by_subject?q=hello
  96
+http://localhost:5984/database/_fti/_design/foo/by_content?q=hello
97 97
 </pre>
98 98
 
99 99
 A fulltext object contains multiple index view declarations. An index view consists of;
@@ -396,9 +396,9 @@ All Dublin Core attributes are indexed and stored if detected in the attachment.
396 396
 <h2>Examples</h2>
397 397
 
398 398
 <pre>
399  
-http://localhost:5984/dbname/_fti/design_doc/view_name?q=field_name:value
400  
-http://localhost:5984/dbname/_fti/design_doc/view_name?q=field_name:value&sort=other_field
401  
-http://localhost:5984/dbname/_fti/design_doc/view_name?debug=true&sort=billing_size&q=body:document AND customer:[A TO C]
  399
+http://localhost:5984/dbname/_fti/_design/foo/view_name?q=field_name:value
  400
+http://localhost:5984/dbname/_fti/_design/foo/view_name?q=field_name:value&sort=other_field
  401
+http://localhost:5984/dbname/_fti/_design/foo/view_name?debug=true&sort=billing_size&q=body:document AND customer:[A TO C]
402 402
 </pre>
403 403
 
404 404
 <h2>Search Results Format</h2>
@@ -509,7 +509,7 @@ The Content-Type of the response is negotiated via the Accept request header lik
509 509
 Calling couchdb-lucene without arguments returns a JSON object with information about the index.
510 510
 
511 511
 <pre>
512  
-http://127.0.0.1:5984/&lt;db>/_fti/&lt;ddoc>/&lt;index
  512
+http://127.0.0.1:5984/&lt;db>/_fti/_design/foo/&lt;index
513 513
 </pre>
514 514
 
515 515
 returns;
@@ -525,13 +525,13 @@ returns;
525 525
 For optimal query speed you can optimize your indexes. This causes the index to be rewritten into a single segment.
526 526
 
527 527
 <pre>
528  
-curl -X POST http://localhost:5984/&lt;db>/_fti/&lt;ddoc>/&lt;index>/_optimize
  528
+curl -X POST http://localhost:5984/&lt;db>/_fti/_design/foo/&lt;index>/_optimize
529 529
 </pre>
530 530
 
531 531
 If you just want to expunge pending deletes, then call;
532 532
 
533 533
 <pre>
534  
-curl -X POST http://localhost:5984/&lt;db>/_fti/&lt;ddoc>/&lt;index>/_expunge
  534
+curl -X POST http://localhost:5984/&lt;db>/_fti/_design/foo/&lt;index>/_expunge
535 535
 </pre>
536 536
 
537 537
 If you recreate databases or frequently change your fulltext functions, you will probably have old indexes lying around on disk. To remove all of them, call;
41  src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
... ...
@@ -0,0 +1,41 @@
  1
+package com.github.rnewson.couchdb.lucene;
  2
+
  3
+import java.util.regex.Matcher;
  4
+import java.util.regex.Pattern;
  5
+
  6
+import javax.servlet.http.HttpServletRequest;
  7
+
  8
+public class PathParts {
  9
+
  10
+	private static final Pattern REGEX = Pattern.compile("^/([^/]+)/([^/]+)/_design/([^/]+)/([^/]+)$");
  11
+
  12
+	private final Matcher matcher;
  13
+
  14
+	public PathParts(final HttpServletRequest req) {
  15
+		this(req.getRequestURI());
  16
+	}	
  17
+
  18
+	public PathParts(final String path) {
  19
+		matcher = REGEX.matcher(path);
  20
+		if (!matcher.matches()) {
  21
+			throw new IllegalArgumentException(path + " is not a valid path");
  22
+		}
  23
+	}
  24
+	
  25
+	public String getKey() {
  26
+		return matcher.group(1);
  27
+	}
  28
+
  29
+	public String getDesignDocumentName() {
  30
+		return "_design/" + matcher.group(3);
  31
+	}
  32
+	
  33
+	public String getDatabaseName() {
  34
+		return matcher.group(2);
  35
+	}
  36
+
  37
+	public String getViewName() {
  38
+		return matcher.group(4);
  39
+	}
  40
+	
  41
+}
4  src/test/java/com/github/rnewson/couchdb/lucene/DocumentConverterTest.java
... ...
@@ -1,12 +1,12 @@
1 1
 package com.github.rnewson.couchdb.lucene;
2 2
 
3  
-import static org.hamcrest.CoreMatchers.*;
  3
+import static org.hamcrest.CoreMatchers.is;
  4
+import static org.hamcrest.CoreMatchers.nullValue;
4 5
 import static org.junit.Assert.assertThat;
5 6
 import net.sf.json.JSONObject;
6 7
 
7 8
 import org.apache.lucene.document.Document;
8 9
 import org.apache.lucene.document.NumericField;
9  
-import org.hamcrest.CoreMatchers;
10 10
 import org.junit.After;
11 11
 import org.junit.Before;
12 12
 import org.junit.Test;
19  src/test/java/com/github/rnewson/couchdb/lucene/PathPartsTest.java
... ...
@@ -0,0 +1,19 @@
  1
+package com.github.rnewson.couchdb.lucene;
  2
+
  3
+import static org.hamcrest.CoreMatchers.is;
  4
+import static org.junit.Assert.assertThat;
  5
+
  6
+import org.junit.Test;
  7
+
  8
+public class PathPartsTest {
  9
+	
  10
+	@Test
  11
+	public void testSearchPath() {
  12
+		final PathParts parts = new PathParts("/local/db1/_design/foo/by_subject");
  13
+		assertThat(parts.getKey(), is("local"));
  14
+		assertThat(parts.getDatabaseName(), is("db1"));
  15
+		assertThat(parts.getDesignDocumentName(), is("_design/foo"));
  16
+		assertThat(parts.getViewName(), is("by_subject"));
  17
+	}
  18
+
  19
+}

0 notes on commit 6b73dc6

Please sign in to comment.
Something went wrong with that request. Please try again.