couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject [08/17] couchdb-mango git commit: List text indexes correctly
Date Wed, 26 Aug 2015 16:39:09 GMT
List text indexes correctly

Text indexes are created in the form of {"name": "fieldname",
"type":"datatype"}. This differs from view based indexes that
are in the form of {"field":"sortdirection"}. When presenting
the text index fields, we display for each field "fieldname":"datatype".

BugzID:46012


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/cdc9fe5c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/cdc9fe5c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/cdc9fe5c

Branch: refs/heads/2787-merge-repos
Commit: cdc9fe5ca09ca3a05e250f881382be6d4f809c9b
Parents: 5df74ff
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Tue Aug 25 13:15:47 2015 -0700
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Tue Aug 25 13:24:04 2015 -0700

----------------------------------------------------------------------
 src/mango_idx_text.erl     | 12 ++++++++++--
 test/01-index-crud-test.py | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/cdc9fe5c/src/mango_idx_text.erl
----------------------------------------------------------------------
diff --git a/src/mango_idx_text.erl b/src/mango_idx_text.erl
index 507e0c2..cce978e 100644
--- a/src/mango_idx_text.erl
+++ b/src/mango_idx_text.erl
@@ -139,13 +139,21 @@ def_to_json([]) ->
 def_to_json([{<<"fields">>, <<"all_fields">>} | Rest]) ->
     [{<<"fields">>, []} | def_to_json(Rest)];
 def_to_json([{fields, Fields} | Rest]) ->
-    [{<<"fields">>, mango_sort:to_json(Fields)} | def_to_json(Rest)];
+    [{<<"fields">>, fields_to_json(Fields)} | def_to_json(Rest)];
 def_to_json([{<<"fields">>, Fields} | Rest]) ->
-    [{<<"fields">>, mango_sort:to_json(Fields)} | def_to_json(Rest)];
+    [{<<"fields">>, fields_to_json(Fields)} | def_to_json(Rest)];
 def_to_json([{Key, Value} | Rest]) ->
     [{Key, Value} | def_to_json(Rest)].
 
 
+fields_to_json([]) ->
+    [];
+fields_to_json([{[{<<"name">>, Name}, {<<"type">>, Type}]} | Rest])
->
+    [{[{Name, Type}]} | fields_to_json(Rest)];
+fields_to_json([{[{<<"type">>, Type}, {<<"name">>, Name}]} | Rest])
->
+    [{[{Name, Type}]} | fields_to_json(Rest)].
+
+
 opts() ->
     [
         {<<"default_analyzer">>, [

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/cdc9fe5c/test/01-index-crud-test.py
----------------------------------------------------------------------
diff --git a/test/01-index-crud-test.py b/test/01-index-crud-test.py
index 1d73a78..31e0b08 100644
--- a/test/01-index-crud-test.py
+++ b/test/01-index-crud-test.py
@@ -223,6 +223,24 @@ class IndexCrudTests(mango.DbPerClass):
         else:
             raise AssertionError("bad index delete")
 
+    def test_create_text_idx(self):
+        fields = [
+            {"name":"stringidx", "type" : "string"},
+            {"name":"booleanidx", "type": "boolean"}
+        ]
+        ret = self.db.create_text_index(fields=fields, name="text_idx_01")
+        assert ret is True
+        for idx in self.db.list_indexes():
+            if idx["name"] != "text_idx_01":
+                continue
+            print idx["def"]
+            assert idx["def"]["fields"] == [
+                {"stringidx": "string"},
+                {"booleanidx": "boolean"}
+            ]
+            return
+        raise AssertionError("index not created")
+
     def test_limit_skip_index(self):
         fields = ["field1"]
         ret = self.db.create_index(fields, name="idx_01")


Mime
View raw message