Repository: lucy
Updated Branches:
  refs/heads/0.5 a6d6d4982 -> 69dfc886f


Add sort_spec param to Simple_Search

The sort_spec parameter was lost when porting Lucy::Simple to C.

Fixes LUCY-307.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/69dfc886
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/69dfc886
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/69dfc886

Branch: refs/heads/0.5
Commit: 69dfc886f50fb9078024b491313af9393b4afb38
Parents: a6d6d49
Author: Nick Wellnhofer <[email protected]>
Authored: Thu Jul 28 14:43:04 2016 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Thu Jul 28 15:12:43 2016 +0200

----------------------------------------------------------------------
 c/sample/search_simple.c    | 2 +-
 core/Lucy/Simple.c          | 5 +++--
 core/Lucy/Simple.cfh        | 4 +++-
 core/Lucy/Test/TestSimple.c | 8 ++++----
 go/build.go                 | 2 +-
 go/lucy/simple.go           | 5 +++--
 go/lucy/simple_test.go      | 2 +-
 7 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/c/sample/search_simple.c
----------------------------------------------------------------------
diff --git a/c/sample/search_simple.c b/c/sample/search_simple.c
index b3e6e66..64b8915 100644
--- a/c/sample/search_simple.c
+++ b/c/sample/search_simple.c
@@ -50,7 +50,7 @@ main(int argc, char *argv[]) {
     Simple *lucy     = Simple_new((Obj*)folder, language);
 
     String *query_str = Str_newf("%s", query_c);
-    Simple_Search(lucy, query_str, 0, 10);
+    Simple_Search(lucy, query_str, 0, 10, NULL);
 
     String *title_str = Str_newf("title");
     String *url_str   = Str_newf("url");

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/core/Lucy/Simple.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Simple.c b/core/Lucy/Simple.c
index 1287bcc..bca5b23 100644
--- a/core/Lucy/Simple.c
+++ b/core/Lucy/Simple.c
@@ -34,6 +34,7 @@
 #include "Lucy/Plan/Schema.h"
 #include "Lucy/Search/Hits.h"
 #include "Lucy/Search/IndexSearcher.h"
+#include "Lucy/Search/SortSpec.h"
 
 Simple*
 Simple_new(Obj *index, String *language) {
@@ -127,7 +128,7 @@ Simple_Add_Doc_IMP(Simple *self, Doc *doc) {
 
 uint32_t
 Simple_Search_IMP(Simple *self, String *query, uint32_t offset,
-                  uint32_t num_wanted) {
+                  uint32_t num_wanted, SortSpec *sort_spec) {
     SimpleIVARS *const ivars = Simple_IVARS(self);
 
     // Flush recent adds; lazily create searcher.
@@ -138,7 +139,7 @@ Simple_Search_IMP(Simple *self, String *query, uint32_t 
offset,
 
     DECREF(ivars->hits);
     ivars->hits = IxSearcher_Hits(ivars->searcher, (Obj*)query, offset,
-                                  num_wanted, NULL);
+                                  num_wanted, sort_spec);
 
     return Hits_Total_Hits(ivars->hits);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/core/Lucy/Simple.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Simple.cfh b/core/Lucy/Simple.cfh
index 292b410..dfb4ca6 100644
--- a/core/Lucy/Simple.cfh
+++ b/core/Lucy/Simple.cfh
@@ -79,10 +79,12 @@ public class Lucy::Simple {
      * found.
      * @param num_wanted The number of hits you would like to see after
      * `offset` is taken into account.
+     * @param sort_spec A [](SortSpec), which will affect how results are
+     * ranked and returned.
      */
     public uint32_t
     Search(Simple *self, String *query, uint32_t offset = 0,
-           uint32_t num_wanted = 10);
+           uint32_t num_wanted = 10, SortSpec *sort_spec = NULL);
 
     /** Return the next hit, or [](cfish:@null) when the iterator is exhausted.
      */

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/core/Lucy/Test/TestSimple.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/TestSimple.c b/core/Lucy/Test/TestSimple.c
index 93fd747..a6c2607 100644
--- a/core/Lucy/Test/TestSimple.c
+++ b/core/Lucy/Test/TestSimple.c
@@ -47,7 +47,7 @@ test_simple(TestBatchRunner *runner) {
         DECREF(doc);
 
         String *query = SSTR_WRAP_C("creamed");
-        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10, NULL);
         TEST_INT_EQ(runner, num_results, 1, "Search works right after add");
     }
 
@@ -59,7 +59,7 @@ test_simple(TestBatchRunner *runner) {
         DECREF(doc);
 
         String *query = SSTR_WRAP_C("creamed");
-        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10, NULL);
         TEST_INT_EQ(runner, num_results, 2, "Search returns total hits");
     }
 
@@ -74,7 +74,7 @@ test_simple(TestBatchRunner *runner) {
         lucy = Simple_new((Obj*)folder, language);
 
         String *query = SSTR_WRAP_C("cream");
-        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10, NULL);
         TEST_INT_EQ(runner, num_results, 3, "commit upon destroy");
 
         HitDoc *hit;
@@ -95,7 +95,7 @@ test_simple(TestBatchRunner *runner) {
         DECREF(doc);
 
         String *query = SSTR_WRAP_C("cream");
-        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10, NULL);
         TEST_INT_EQ(runner, num_results, 4,
                     "Search uses correct EasyAnalyzer");
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 8353d66..73c2f87 100644
--- a/go/build.go
+++ b/go/build.go
@@ -138,7 +138,7 @@ func runCFC() {
 func specClasses(parcel *cfc.Parcel) {
        simpleBinding := cfc.NewGoClass(parcel, "Lucy::Simple")
        simpleBinding.SpecMethod("Add_Doc", "AddDoc(doc interface{}) error")
-       simpleBinding.SpecMethod("Search", "Search(string, int, int) (int, 
error)")
+       simpleBinding.SpecMethod("Search", "Search(string, int, int, SortSpec) 
(int, error)")
        simpleBinding.SpecMethod("Next", "Next(hit interface{}) bool")
        simpleBinding.SpecMethod("", "Error() error")
        simpleBinding.SetSuppressCtor(true)

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/go/lucy/simple.go
----------------------------------------------------------------------
diff --git a/go/lucy/simple.go b/go/lucy/simple.go
index b4e6ff4..cf38043 100644
--- a/go/lucy/simple.go
+++ b/go/lucy/simple.go
@@ -96,12 +96,13 @@ func (s *SimpleIMP) AddDoc(doc interface{}) error {
        })
 }
 
-func (s *SimpleIMP) Search(query string, offset, numWanted int) (totalHits 
int, err error) {
+func (s *SimpleIMP) Search(query string, offset, numWanted int, sortSpec 
SortSpec) (totalHits int, err error) {
        err = clownfish.TrapErr(func() {
                self := (*C.lucy_Simple)(clownfish.Unwrap(s, "s"))
                qStringC := (*C.cfish_String)(clownfish.GoToClownfish(query, 
unsafe.Pointer(C.CFISH_STRING), false))
                defer C.cfish_decref(unsafe.Pointer(qStringC))
-               totalHits = int(C.LUCY_Simple_Search(self, qStringC, 
C.uint32_t(offset), C.uint32_t(numWanted)))
+               sortSpecC := 
(*C.lucy_SortSpec)(clownfish.UnwrapNullable(sortSpec))
+               totalHits = int(C.LUCY_Simple_Search(self, qStringC, 
C.uint32_t(offset), C.uint32_t(numWanted), sortSpecC))
        })
        return totalHits, err
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/69dfc886/go/lucy/simple_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/simple_test.go b/go/lucy/simple_test.go
index cf2081e..677b2c9 100644
--- a/go/lucy/simple_test.go
+++ b/go/lucy/simple_test.go
@@ -43,7 +43,7 @@ func TestSimpleBasics(t *testing.T) {
                t.Errorf("AddDoc with Doc: %v", err)
        }
 
-       count, err := simple.Search("foo", 0, 10)
+       count, err := simple.Search("foo", 0, 10, nil)
        if count != 3 || err != nil {
                t.Errorf("Search: %d, %v", count, err)
        }

Reply via email to