Skip to content

Commit

Permalink
Merge pull request #7 from stevenferrer/feature/filter-gram-sizes
Browse files Browse the repository at this point in the history
include maxGram and minGram in schema.Filter
  • Loading branch information
stevenferrer authored Jun 28, 2020
2 parents f93d24f + dfe406a commit 892e4d4
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 199 deletions.
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
.PHONY: test
test:
go test -v -cover ./...
SOLR_INST ?="solr-go-test"
COLLECTION ?= "gettingstarted"

.PHONY: solr
solr:
docker rm -f solr-test || true
docker run -d -p 8983:8983 --name solr-test solr:latest solr-precreate gettingstarted
solr: stop-solr
docker run -d -p 8983:8983 --name $(SOLR_INST) solr:latest solr-precreate $(COLLECTION)

.PHONY: stop-solr
stop-solr:
docker rm -f solr-test || true
docker rm -f $(SOLR_INST) || true
58 changes: 51 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,65 @@
[![CircleCI](https://circleci.com/gh/stevenferrer/solr-go.svg?style=shield)](https://circleci.com/gh/stevenferrer/solr-go)
[![Coverage Status](https://coveralls.io/repos/github/stevenferrer/solr-go/badge.svg?branch=master)](https://coveralls.io/github/stevenferrer/solr-go?branch=master)

# solr-go
# Solr-Go

[Solr](https://lucene.apache.org/solr/) client for [Go](http://go.dev/).
[Solr](https://lucene.apache.org/solr/) client for [Go](http://go.dev/).

```go

import (
"context"
// Import the package that you need
solrquery "github.com/stevenferrer/solr-go/query"
)

func main() {
// Initialize the query client
queryClient := solrquery.NewClient("localhost", 8983)

// Start querying!
queryResp, err := queryClient.Query(
context.Background(),
"techproducts", // name of your collection
map[string]interface{}{
"query": "{!lucene df=name v=iPod}",
},
)
...
}
```

## Notes
* This is a *WORK IN-PROGRESS*, API might change a lot before *v1*
* Currently being used in my project
* Tested on [Solr 8.5](https://lucene.apache.org/solr/guide/8_5/)

## Contents

- [solr-go](#solr-go)
- [Solr-Go](#solr-go)
- [Notes](#notes)
- [Contents](#contents)
- [Installation and usage](#installation-and-usage)
- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [Contributing](#contributing)

## Installation and usage
## Installation

You can include it in your *go.mod* by running in your terminal (assuming you're inside the project directory):

```console
$ go get github.com/stevenferrer/solr-go
```

## Usage

Detailed documentation shall follow. For now you can start looking at the examples inside each package directory.

TODO
* [Index API example](./index/examples/main.go)
* [Query API example](./query/example/main.go)
* [Schema API example](./schema/example/main.go)
* Suggester API example - TODO

## Features

Expand Down Expand Up @@ -46,4 +90,4 @@ TODO

## Contributing

This is a work in-progres, any contributions are very welcome!
This is a **work in-progress**, any contributions are very welcome!
11 changes: 8 additions & 3 deletions schema/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,14 @@ func TestModifySchema(t *testing.T) {
// with 2 analyzers
IndexAnalyzer: &schema.Analyzer{
Tokenizer: &schema.Tokenizer{
Class: "solr.PathHierarchyTokenizerFactory",
Delimeter: "/",
Class: "solr.StandardTokenizerFactory",
},
Filters: []schema.Filter{
{
Class: "solr.EdgeNGramFilterFactory",
MinGramSize: 1,
MaxGramSize: 100,
},
},
},
QueryAnalyzer: &schema.Analyzer{
Expand All @@ -327,7 +333,6 @@ func TestModifySchema(t *testing.T) {
},
},
},

{
name: "replace field type with error",
command: "replace-field-type",
Expand Down
18 changes: 7 additions & 11 deletions schema/fixtures/add-copy-field-ok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-dynamic-field":{"name":"*_shelf","stored":true,"type":"string"}}'
body: '{"add-dynamic-field":{"name":"*_shelf","type":"string","stored":true}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,14 +14,12 @@ interactions:
{
"responseHeader":{
"status":0,
"QTime":568}}
"QTime":1244}}
headers:
Content-Length:
- "57"
- "58"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand All @@ -34,7 +32,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"add-copy-field":{"dest":"_text_","source":"*_shelf"}}'
body: '{"add-copy-field":{"source":"*_shelf","dest":"_text_"}}'
form: {}
headers:
Content-Type:
Expand All @@ -46,14 +44,12 @@ interactions:
{
"responseHeader":{
"status":0,
"QTime":533}}
"QTime":866}}
headers:
Content-Length:
- "57"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
6 changes: 2 additions & 4 deletions schema/fixtures/add-copy-field-with-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interactions:
{
"responseHeader":{
"status":400,
"QTime":1},
"QTime":2},
"error":{
"metadata":[
"error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject",
Expand All @@ -29,9 +29,7 @@ interactions:
Content-Length:
- "440"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
8 changes: 3 additions & 5 deletions schema/fixtures/add-dynamic-field-ok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-dynamic-field":{"name":"*_wtf","stored":true,"type":"string"}}'
body: '{"add-dynamic-field":{"name":"*_wtf","type":"string","stored":true}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,14 +14,12 @@ interactions:
{
"responseHeader":{
"status":0,
"QTime":512}}
"QTime":987}}
headers:
Content-Length:
- "57"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
15 changes: 6 additions & 9 deletions schema/fixtures/add-dynamic-field-with-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-dynamic-field":{}}'
body: '{"add-dynamic-field":{"name":""}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,24 +14,21 @@ interactions:
{
"responseHeader":{
"status":400,
"QTime":1},
"QTime":3},
"error":{
"metadata":[
"error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject",
"root-error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject"],
"details":[{
"add-dynamic-field":{},
"errorMessages":["'name' is a required field",
"'type' is a required field"]}],
"add-dynamic-field":{"name":""},
"errorMessages":["'type' is a required field"]}],
"msg":"error processing commands",
"code":400}}
headers:
Content-Length:
- "441"
- "410"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
8 changes: 3 additions & 5 deletions schema/fixtures/add-field-ok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-field":{"name":"sell_by","stored":true,"type":"pdate"}}'
body: '{"add-field":{"name":"sell_by","type":"pdate","stored":true}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,14 +14,12 @@ interactions:
{
"responseHeader":{
"status":0,
"QTime":1066}}
"QTime":1265}}
headers:
Content-Length:
- "58"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
10 changes: 4 additions & 6 deletions schema/fixtures/add-field-type-ok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-field-type":{"class":"solr.TextField","indexAnalyzer":{"tokenizer":{"class":"solr.PathHierarchyTokenizerFactory","delimiter":"/"}},"name":"myNewTextField","queryAnalyzer":{"tokenizer":{"class":"solr.KeywordTokenizerFactory"}}}}'
body: '{"add-field-type":{"name":"myNewTextField","class":"solr.TextField","indexAnalyzer":{"tokenizer":{"class":"solr.StandardTokenizerFactory"},"filters":[{"class":"solr.EdgeNGramFilterFactory","minGramSize":1,"maxGramSize":100}]},"queryAnalyzer":{"tokenizer":{"class":"solr.KeywordTokenizerFactory"}}}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,14 +14,12 @@ interactions:
{
"responseHeader":{
"status":0,
"QTime":921}}
"QTime":1553}}
headers:
Content-Length:
- "57"
- "58"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
13 changes: 5 additions & 8 deletions schema/fixtures/add-field-type-with-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-field-type":{}}'
body: '{"add-field-type":{"name":""}}'
form: {}
headers:
Content-Type:
Expand All @@ -20,18 +20,15 @@ interactions:
"error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject",
"root-error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject"],
"details":[{
"add-field-type":{},
"errorMessages":["'name' is a required field",
"'class' is a required field"]}],
"add-field-type":{"name":""},
"errorMessages":["'class' is a required field"]}],
"msg":"error processing commands",
"code":400}}
headers:
Content-Length:
- "439"
- "408"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
15 changes: 6 additions & 9 deletions schema/fixtures/add-field-with-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"add-field":{}}'
body: '{"add-field":{"name":""}}'
form: {}
headers:
Content-Type:
Expand All @@ -14,24 +14,21 @@ interactions:
{
"responseHeader":{
"status":400,
"QTime":1159},
"QTime":10},
"error":{
"metadata":[
"error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject",
"root-error-class","org.apache.solr.api.ApiBag$ExceptionWithErrObject"],
"details":[{
"add-field":{},
"errorMessages":["'name' is a required field",
"'type' is a required field"]}],
"add-field":{"name":""},
"errorMessages":["'type' is a required field"]}],
"msg":"error processing commands",
"code":400}}
headers:
Content-Length:
- "436"
- "403"
Content-Security-Policy:
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self';
font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self';
style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
- default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
Content-Type:
- text/plain;charset=utf-8
X-Content-Type-Options:
Expand Down
Loading

0 comments on commit 892e4d4

Please sign in to comment.