I’m @vanng822 aka @vannhu-nguyen
I'm @Instagram
I'm @LinkedIn
vanng822 / go-solr Goto Github PK
View Code? Open in Web Editor NEWSolr client in Go, core admin, add docs, update, delete, search and more
License: MIT License
Solr client in Go, core admin, add docs, update, delete, search and more
License: MIT License
I’m @vanng822 aka @vannhu-nguyen
I'm @Instagram
I'm @LinkedIn
Request
Reason :
I want to use it in a Proxy environment
Make a request
connection.go
Line:16
var transport = http.Transport{}
Don't initialize with empty, just use
DefaultTransport
or
or add the following function
func SetTransport(h http.Transport) {
transport = h
}
Example :
http.DefaultTransport = &http.Transport{ Proxy: http.ProxyURL(proxyUrl) }
I want to use defaultTransport and use it around like
Or
tr := &http.Transport{
ResponseHeaderTimeout: 30 * time.Second,
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 2 * time.Second,
}).DialContext,
MaxIdleConns: 0,
IdleConnTimeout: 30 * time.Second,
TLSHandshakeTimeout: 2 * time.Second, }),
Second, MaxIdleConnsPerHost: 100,
//DisableKeepAlives: false,
DisableKeepAlives: true,
}
solr.SetTransport(tr)
Please.
I'd like to use this with Solr 7. Will I have any problems?
we should have 2 type of response for raw response from solr, one for select and other get method, this should have Status property for quick access and one for update/post which should contain Success to indicate if the operation was successfully.
Suggestion:
I already have json docs as string
following code snippet is used to construct a valid json string.
func StoreInSolr(sc *solr.SolrInterface, docs []string) (*solr.SolrUpdateResponse, error) {
params := &url.Values{}
params.Add("commit", "true")
var lines []string
for _, doc := range docs {
if len(strings.TrimSpace(doc)) == 0 {
continue
}
lines = append(lines, doc)
}
data := fmt.Sprintf("[%s]\n", strings.Join(lines, ","))
fmt.Printf("data: %+v\n", data)
resp, err := sc.Update(data, params)
return resp, err
}
both resp and err indicate success:
&solr.SolrUpdateResponse{Success:true, Result:map[string]interface {}{"responseHeader":map[string]interface {}{"QTime":3, "status":0}}}, err: <nil>
but on solr debug logs i get
o.a.s.h.l.JsonLoader Can't have a value here. Unexpected STRING at [1]
This has to do with json string format but json is valid.
any pointers appreciated .
We have to make sure that we can recover and properly return the error. This can also happen when we get connection refused for instance or response is an xml/html instead
i want to add solr stream export support in project by adding an response parser base on binlog encode format,
i have make the test case code passed ,i want to commit a PR later ,is that OK?
We missed to update both places
This should be a new Type where we will make request to endpoint "/solr/admin/cores"
You should be able to pass parameters so one can specify: action, core and so on.
This should also support basic auth
Good Job! How to get debug info for the raw query sent to solr?
This can be useful for make query to /select /mlt /suggest or /spell
This method should implement in Connection and return SolrResponse
Add support to pass standard context.Context to Search and other functions in order to handle cancellations and graceful shutdowns properly.
Sample use:
package main
import (
"context"
"github.com/vanng822/go-solr/solr"
"fmt"
)
func main() {
ctx := context.Background()
si, _ := solr.NewSolrInterfaceWithCtx(ctx, "http://localhost:8983/solr", "collection1")
query := solr.NewQuery()
query.Q("*:*")
s := si.SearchWithCtx(ctx, query)
r, _ := s.Result(nil)
fmt.Println(r.Results.Docs)
}
Interesting params:
.Sort(sortBy string)
.FilterQuery(fq string)
.FieldList(fl string)
.Geofilt(latitude float64, longitude float64, sfield string, distance float64)
.DefType(defType string)
.BoostFunctions(bf string)
.BoostQuery(bq string)
.QueryFields(qf string)
Probably the same for both update and select case
It should take an optional query string for possibility to specify more, for instance
http://localhost:8983/solr/update?optimize=true&maxSegments=10&waitFlush=false
where we should lock http://localhost:8983/solr/update?optimize=true and append the optional query into it
Since we not checking schema in this package we should provide an easy way to get schema in case application need it.
Investigate and see how we can implement a generic grouped parser.
See https://wiki.apache.org/solr/CoreAdmin STATUS
This makes the configuration easier, solrUrl will be up to solr and applications can use it for both Select, Update and Core Admin. But for Update and Select we need core name. This is probably best a property of Connection but should be able to specify when creating a new SolrInterface. Can be interesting that corename can be switched as well.
interface conversion: interface {} is nil, not map[string]interface {}:
panic(0x2423640, 0xc0168b8930)
C:/Go/src/runtime/panic.go:513 +0x1c7
github.com/vanng822/go-solr/solr.(*StandardResultParser).Parse(0x3410718, 0xc07f1360e0, 0x6, 0xc015d9cf38, 0xc07f1360e0)
C:/Users/Margaryta/GoSrc/src/bitbucket.org/repustate/repustate-go/src/github.com/vanng822/go-solr/solr/parser.go:130 +0x6a5
github.com/vanng822/go-solr/solr.(*Search).Result(0xc032187710, 0x0, 0x0, 0x0, 0x1, 0xc04ed9c0b0)
C:/Users/Margaryta/GoSrc/src/bitbucket.org/repustate/repustate-go/src/github.com/vanng822/go-solr/solr/search.go:72 +0xbe
Happens when Solr fails to load core to execute solr.Search
, in such cases Solr instance returns error
object like :
"error":{
"metadata":[
"error-class","org.apache.solr.core.SolrCoreInitializationException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"SolrCore 'clientindices' is not available due to init failure: Could not load configuration from directory /var/solr/data/configsets/_default",
"trace":"org.apache.solr.core.SolrCoreInitializationException: SolrCore 'clientindices' is not available due to init failure: Could not load configuration from directory /var/solr/data/configsets/_default\n\tat org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:1593)\n\tat org.apache.solr.servlet.HttpSolrCall.init(HttpSolrCall.java:249)\n\tat .
...
org.apache.solr.servlet.HttpSolrCall.handleAdmin(HttpSolrCall.java:734)\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:496)\n\t... 36 more\n",
"code":500}}
See si.Add method, can be good to support batch commit in the beginning.
and https://wiki.apache.org/solr/UpdateJSON
Provide possibility to call with commit flag
In my project, I have a requirement of adding spellcheck and suggestions for solr search. I would like to know whether you will be able to add these options to SolrResponse or do you plan to provide raw response support in your package?
Figure out how to send
http://wiki.apache.org/solr/MoreLikeThis
Implement a new method in Search to do query to mlt handler
Can be good to rethink if we can give an option for other to provide the Document type themself. Maybe document should be an interface with some basic setters and getters
See si.Delete
and https://wiki.apache.org/solr/UpdateJSON#Update_Commands
The following error is coming when message is being created in delete function in solr.go
Failed to evaluate expression - Message (type github.com/vanng822/go-solr/solr.M) is not a struct
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.