Last active
December 21, 2015 20:09
-
-
Save philipsoutham/6359668 to your computer and use it in GitHub Desktop.
Simple test to check functionality of golucy binding.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/philipsoutham/golucy" | |
) | |
func main() { | |
ixLocation := "/tmp/lucy_index" | |
schema := &golucy.Schema{ | |
PlanItems: []*golucy.PlanItem{ | |
&golucy.PlanItem{Field: "id", Type: golucy.StringType, Options: &golucy.PlanItemOptions{Stored: true, Indexed: false}}, | |
&golucy.PlanItem{Field: "title", Type: golucy.FullTextType}, | |
&golucy.PlanItem{Field: "content", Type: golucy.FullTextType}, | |
}, | |
} | |
defer schema.Close() | |
schema.Commit() | |
idx := &golucy.Index{ | |
Schema: schema, | |
Location: ixLocation, | |
} | |
defer idx.Close() | |
valueRows := []*golucy.IndexValueRow{ | |
&golucy.IndexValueRow{ | |
Columns: []*golucy.IndexValueColumn{ | |
&golucy.IndexValueColumn{ | |
Field: "id", | |
Value: "1", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "title", | |
Value: "Lorem ipsum", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "content", | |
Value: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | |
}, | |
}, | |
}, | |
&golucy.IndexValueRow{ | |
Columns: []*golucy.IndexValueColumn{ | |
&golucy.IndexValueColumn{ | |
Field: "id", | |
Value: "2", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "title", | |
Value: "Ut enim", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "content", | |
Value: "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | |
}, | |
}, | |
}, | |
&golucy.IndexValueRow{ | |
Columns: []*golucy.IndexValueColumn{ | |
&golucy.IndexValueColumn{ | |
Field: "id", | |
Value: "3", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "title", | |
Value: "Duis aute", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "content", | |
Value: "Duis aute irure dolor in reprehenderit in voluptate velit essei cillum dolore eu fugiat nulla pariatur.", | |
}, | |
}, | |
}, | |
&golucy.IndexValueRow{ | |
Columns: []*golucy.IndexValueColumn{ | |
&golucy.IndexValueColumn{ | |
Field: "id", | |
Value: "4", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "title", | |
Value: "Excepteur sint", | |
}, | |
&golucy.IndexValueColumn{ | |
Field: "content", | |
Value: "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", | |
}, | |
}, | |
}, | |
} | |
writer := idx.GetIndexWriter(golucy.IndexTruncate) | |
for _, row := range valueRows { | |
writer(row.Columns...) | |
} | |
idx.Commit() | |
search := &golucy.Search{Location: ixLocation} | |
defer search.Close() | |
searcher := search.GetSearcher() | |
hits, value := searcher("ullamco", "title", 0, 100) | |
fmt.Printf("hits: %d, value: %+v\n", hits, value) | |
hits, value = searcher("ut OR laborum", "title", 0, 100) | |
fmt.Printf("hits: %d, value: %+v\n", hits, value) | |
hits, value = searcher("\"fugiat nulla\"", "title", 0, 100) | |
fmt.Printf("hits: %d, value: %+v\n", hits, value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment