Skip to content
Snippets Groups Projects
Commit 3b4b6075 authored by ale's avatar ale
Browse files

Use a phrase query for the title on google books

Should help improve the quality of matches.
parent c9254c36
Branches
Tags
No related merge requests found
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"net/url" "net/url"
"path/filepath" "path/filepath"
...@@ -79,9 +80,7 @@ func googleBooksQuery(m *Metadata) string { ...@@ -79,9 +80,7 @@ func googleBooksQuery(m *Metadata) string {
// If we have explicitly tagged metadata, use it. // If we have explicitly tagged metadata, use it.
if len(m.Title) > 0 { if len(m.Title) > 0 {
for _, s := range strings.Fields(m.Title) { query = append(query, fmt.Sprintf("intitle:\"%s\"", m.Title))
query = append(query, fmt.Sprintf("intitle:%s", s))
}
} }
if len(m.Creator) > 0 { if len(m.Creator) > 0 {
for _, author := range m.Creator { for _, author := range m.Creator {
...@@ -161,6 +160,7 @@ func (r *googleBooksRefiner) Lookup(m *Metadata) ([]*Metadata, error) { ...@@ -161,6 +160,7 @@ func (r *googleBooksRefiner) Lookup(m *Metadata) ([]*Metadata, error) {
if qstr == "" { if qstr == "" {
return nil, errors.New("insufficient metadata for query") return nil, errors.New("insufficient metadata for query")
} }
log.Printf("googlebooks query: %s", qstr)
values := make(url.Values) values := make(url.Values)
values.Set("q", qstr) values.Set("q", qstr)
if *googleAPIKey != "" { if *googleAPIKey != "" {
...@@ -169,6 +169,7 @@ func (r *googleBooksRefiner) Lookup(m *Metadata) ([]*Metadata, error) { ...@@ -169,6 +169,7 @@ func (r *googleBooksRefiner) Lookup(m *Metadata) ([]*Metadata, error) {
uri := "http://books.google.com/books/feeds/volumes?" + values.Encode() uri := "http://books.google.com/books/feeds/volumes?" + values.Encode()
resp, err := googleBooksGet(uri) resp, err := googleBooksGet(uri)
if err != nil { if err != nil {
log.Printf("googlebooks error: %v", err)
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment