Browse Source

First commit: dump slice, bleve demo.

Frederic G. MARAND 4 years ago
commit
38b060cfcc

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+.idea/$CACHE_FILE$
+.idea/$PRODUCT_WORKSPACE_FILE$

+ 2 - 0
.idea/.gitignore

@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml

+ 18 - 0
.idea/codeStyles/Project.xml

@@ -0,0 +1,18 @@
+<component name="ProjectCodeStyleConfiguration">
+  <code_scheme name="Project" version="173">
+    <option name="SOFT_MARGINS" value="80" />
+    <HTMLCodeStyleSettings>
+      <option name="HTML_KEEP_BLANK_LINES" value="1" />
+      <option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="html" />
+      <option name="HTML_ENFORCE_QUOTES" value="true" />
+    </HTMLCodeStyleSettings>
+    <codeStyleSettings language="HTML">
+      <option name="WRAP_ON_TYPING" value="1" />
+      <indentOptions>
+        <option name="INDENT_SIZE" value="2" />
+        <option name="CONTINUATION_INDENT_SIZE" value="2" />
+        <option name="TAB_SIZE" value="2" />
+      </indentOptions>
+    </codeStyleSettings>
+  </code_scheme>
+</component>

+ 5 - 0
.idea/codeStyles/codeStyleConfig.xml

@@ -0,0 +1,5 @@
+<component name="ProjectCodeStyleConfiguration">
+  <state>
+    <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
+  </state>
+</component>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptSettings">
+    <option name="languageLevel" value="ES6" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/tooling.iml" filepath="$PROJECT_DIR$/.idea/tooling.iml" />
+    </modules>
+  </component>
+</project>

+ 24 - 0
.idea/runConfigurations/Bleve_demo.xml

@@ -0,0 +1,24 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="Bleve demo" type="GoApplicationRunConfiguration" factoryName="Go Application" editBeforeRun="true" activateToolWindowBeforeRun="false">
+    <module name="tooling" />
+    <working_directory value="$PROJECT_DIR$/blevedemo" />
+    <go_parameters value="-i -o blevedemo" />
+    <parameters value="final" />
+    <EXTENSION ID="net.ashald.envfile">
+      <option name="IS_ENABLED" value="false" />
+      <option name="IS_SUBST" value="false" />
+      <option name="IS_PATH_MACRO_SUPPORTED" value="false" />
+      <option name="IS_IGNORE_MISSING_FILES" value="false" />
+      <option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
+      <ENTRIES>
+        <ENTRY IS_ENABLED="true" PARSER="runconfig" />
+      </ENTRIES>
+    </EXTENSION>
+    <kind value="PACKAGE" />
+    <filePath value="$PROJECT_DIR$/" />
+    <package value="code.osinet.fr/fgm/tooling/blevedemo" />
+    <directory value="$PROJECT_DIR$/" />
+    <output_directory value="$PROJECT_DIR$/blevedemo" />
+    <method v="2" />
+  </configuration>
+</component>

+ 8 - 0
.idea/tooling.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 1 - 0
blevedemo/.gitignore

@@ -0,0 +1 @@
+blevedemo

+ 70 - 0
blevedemo/blevedemo.go

@@ -0,0 +1,70 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"os"
+
+	"github.com/blevesearch/bleve"
+)
+
+const IndexPath = "example.bleve"
+
+type Named struct {
+	Name string
+}
+
+func createIndex() bleve.Index {
+	// open a new index
+	mapping := bleve.NewIndexMapping()
+	index, err := bleve.New(IndexPath, mapping)
+	if err != nil {
+		panic(err)
+	}
+
+	// index some data
+	err = index.Index("latin", Named{"quadra"})
+	if err != nil {
+		panic(err)
+	}
+	err = index.Index("pirate", Named{"The heavy-hearted kraken fiery breaks the jack."})
+	if err != nil {
+		panic(err)
+	}
+	err = index.Index("sf", Named{"Cosmonauts experiment from flights like the final ships."})
+	if err != nil {
+		panic(err)
+	}
+	err = index.Index("cuisine", Named{"Try breaking steak pilaf garnished with the gravy."})
+	if err != nil {
+		panic(err)
+	}
+	err = index.Index("esoteric", "The death of fearing doers is unbiased, final and from the heart.")
+	if err != nil {
+		panic(err)
+	}
+	return index
+}
+
+func main() {
+	index, err := bleve.Open(IndexPath)
+	if err != nil {
+		if err == bleve.ErrorIndexPathDoesNotExist {
+			index = createIndex()
+		} else {
+			panic(err)
+		}
+	}
+	defer index.Close()
+
+	// search for some text
+	//query := bleve.NewMatchQuery(os.Args[1])
+	query := bleve.NewFuzzyQuery(os.Args[1])
+	query.SetFuzziness(2)
+	search := bleve.NewSearchRequest(query)
+	searchResults, err := index.Search(search)
+	if err != nil {
+		log.Fatal(err)
+	}
+	fmt.Println(searchResults)
+}

+ 1 - 0
blevedemo/example.bleve/index_meta.json

@@ -0,0 +1 @@
+{"storage":"boltdb","index_type":"upside_down"}

BIN
blevedemo/example.bleve/store


+ 55 - 0
dump/slice.go

@@ -0,0 +1,55 @@
+package main
+
+import (
+	"fmt"
+	"strings"
+	"unsafe"
+)
+
+type slice struct {
+	arrayPtr uint
+	len      uint
+	cap      uint
+}
+
+func (s slice) Data() []byte {
+	var p *byte
+	var i uint
+	res := make([]byte, s.len)
+	for i = 0; i < s.len; i++ {
+		p = (*byte)(unsafe.Pointer(uintptr(s.arrayPtr) + uintptr(i)))
+		res[i] = *p
+	}
+
+	return res
+}
+
+func Dump(slicePtr *[]byte) {
+	var n uintptr = uintptr(unsafe.Pointer(slicePtr))
+	var s *slice = (*slice)(unsafe.Pointer(n))
+	fmt.Println(*s)
+	fmt.Printf("Len: %d, Cap: %d: Data:\n", s.len, s.cap)
+	fmt.Printf("%#v\n", s.Data())
+}
+
+func main() {
+	var max byte = 13
+	a := make([]byte, max, 64)
+	var i byte
+	for i = 0; i < max; i++ {
+		a[i] = '@' + i
+	}
+	fmt.Println(a, len(a), cap(a))
+
+	Dump(&a)
+
+	var z int
+	fmt.Println(unsafe.Sizeof(z))
+
+	r := strings.NewReader("ceci est une chaîne")
+	var s []byte
+
+	n, err := r.ReadAt(s, 4)
+	fmt.Println("Read: %n (%v): %#v\n", n, err, s)
+
+}