All Projects → takezoe → Solr Scala Client

takezoe / Solr Scala Client

Licence: apache-2.0
Solr Client for Scala

Programming Languages

scala
5932 projects

Labels

Projects that are alternatives of or similar to Solr Scala Client

Solrnet
Solr client for .Net
Stars: ✭ 853 (+891.86%)
Mutual labels:  solr
Ik Analyzer Solr
ik-analyzer for solr 7.x-8.x
Stars: ✭ 1,017 (+1082.56%)
Mutual labels:  solr
Solr Express
A simple and lightweight query .NET library for Solr, in a controlled, buildable and fail fast way.
Stars: ✭ 66 (-23.26%)
Mutual labels:  solr
Git To Solr
Index git history into a Solr repository
Stars: ✭ 31 (-63.95%)
Mutual labels:  solr
Solrcloudpy
python library for interacting with SolrCloud
Stars: ✭ 37 (-56.98%)
Mutual labels:  solr
Elasticsearch Synonyms
Curated synonym files and Helpers for Elasticsearch Synonym Token Filter
Stars: ✭ 51 (-40.7%)
Mutual labels:  solr
Dockerfiles
50+ DockerHub public images for Docker & Kubernetes - Hadoop, Kafka, ZooKeeper, HBase, Cassandra, Solr, SolrCloud, Presto, Apache Drill, Nifi, Spark, Consul, Riak, TeamCity and DevOps tools built on the major Linux distros: Alpine, CentOS, Debian, Fedora, Ubuntu
Stars: ✭ 847 (+884.88%)
Mutual labels:  solr
Blog
一款简洁响应式博客系统
Stars: ✭ 72 (-16.28%)
Mutual labels:  solr
Nagios Plugins
450+ AWS, Hadoop, Cloud, Kafka, Docker, Elasticsearch, RabbitMQ, Redis, HBase, Solr, Cassandra, ZooKeeper, HDFS, Yarn, Hive, Presto, Drill, Impala, Consul, Spark, Jenkins, Travis CI, Git, MySQL, Linux, DNS, Whois, SSL Certs, Yum Security Updates, Kubernetes, Cloudera etc...
Stars: ✭ 1,000 (+1062.79%)
Mutual labels:  solr
Solrj Example
solrj示例
Stars: ✭ 56 (-34.88%)
Mutual labels:  solr
Solrbulk
SOLR bulk indexing utility for the command line.
Stars: ✭ 35 (-59.3%)
Mutual labels:  solr
Shutterstock Heatmap Toolkit
Shutterstock's interactive heatmap toolkit powered by heatmap.js and Solr
Stars: ✭ 37 (-56.98%)
Mutual labels:  solr
Hadoop Solr
Code to index HDFS to Solr using MapReduce
Stars: ✭ 51 (-40.7%)
Mutual labels:  solr
Wukong
An ORM Client library for SolrCloud http://wukong.readthedocs.io/en/latest/
Stars: ✭ 10 (-88.37%)
Mutual labels:  solr
Awesome Solr
A curated list of Awesome Apache Solr links and resources.
Stars: ✭ 69 (-19.77%)
Mutual labels:  solr
Solarium
PHP Solr client library
Stars: ✭ 849 (+887.21%)
Mutual labels:  solr
Datafari
Open Source, Distributed, Big Data Enterprise Search Engine
Stars: ✭ 47 (-45.35%)
Mutual labels:  solr
Solrplugins
Dice Solr Plugins from Simon Hughes Dice.com
Stars: ✭ 86 (+0%)
Mutual labels:  solr
Vectorsinsearch
Dice.com repo to accompany the dice.com 'Vectors in Search' talk by Simon Hughes, from the Activate 2018 search conference, and the 'Searching with Vectors' talk from Haystack 2019 (US). Builds upon my conceptual search and semantic search work from 2015
Stars: ✭ 71 (-17.44%)
Mutual labels:  solr
Open Semantic Search Apps
Python/Django based webapps and web user interfaces for search, structure (meta data management like thesaurus, ontologies, annotations and named entities) and data import (ETL like text extraction, OCR and crawling filesystems or websites)
Stars: ✭ 55 (-36.05%)
Mutual labels:  solr

solr-scala-client Build Status Maven Central License

The simple Apache Solr client for Scala. This is based on the SolrJ and provides optimal interface for Scala.

Add the following dependency into your build.sbt to use solr-scala-client.

libraryDependencies += "com.github.takezoe" %% "solr-scala-client" % "0.0.24"

If you want to test SNAPSHOT version, add the following dependency instead of above:

resolvers += "sonatype-oss-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "com.github.takezoe" %% "solr-scala-client" % "x.x.x-SNAPSHOT"

This is a simplest example to show usage of solr-scala-client.

import com.github.takezoe.solr.scala._

val client = new SolrClient("http://localhost:8983/solr")

// register
client
  .add(Map("id"->"001", "manu" -> "Lenovo", "name" -> "ThinkPad X201s"))
  .add(Map("id"->"002", "manu" -> "Lenovo", "name" -> "ThinkPad X220"))
  .add(Map("id"->"003", "manu" -> "Lenovo", "name" -> "ThinkPad X121e"))
  .commit

// query
val result = client.query("name: %name%")
  .fields("id", "manu", "name")
  .sortBy("id", Order.asc)
  .getResultAsMap(Map("name" -> "ThinkPad"))

result.documents.foreach { doc: Map[String, Any] =>
  println("id: " + doc("id"))
  println("  manu: " + doc("manu"))
  println("  name: " + doc("name"))
}

It's also possible to use the case class as the search result and parameters instead of Map.

// query
val result = client.query("name: %name%")
  .fields("id", "manu", "name")
  .sortBy("id", Order.asc)
  .getResultAs[Product](Param(name = "ThinkPad"))

result.documents.foreach { product: Product =>
  println("id: " + product.id)
  println("  manu: " + product.manu)
  println("  name: " + product.name)
}

Query Syntax

Following notations are available to embed variables to the query:

  • %VAR_NAME% : place holder to set a single word (parameter would be escaped)
  • ?VAR_NAME? : place holder to set an expression (&, | and ! are available in an expression)
  • $VAR_NAME$ : string replacement (parameter would be not escaped)

See examples of parameterized queries and assembled Solr queries.

// %VAR_NAME% (Single keyword)
client.query("name: %name%").getResultAsMap(Map("name" -> "ThinkPad X201s"))
  // => name:"ThinkPad X201s"

// $VAR_NAME$ (String replacement)
client.query("name: $name$").getResultAsMap(Map("name" -> "ThinkPad AND X201s"))
  // => name:ThinkPad AND X201s

// ?VAR_NAME? (Expression)
client.query("name: ?name?").getResultAsMap(Map("name" -> "ThinkPad & X201s"))
  // => name:("ThinkPad" AND "X201s")

Highlight

Configure the query to return the highlighted content by QueryBuilder#highlight(). The highlighted content is set as the "highlight" property to the Map or the case class.

val result = client.query("content: Scala")
  // NOTE: unique key field is required.
  .fields("id")
  // Specify the highlighted field, prefix and postfix (prefix and postfix are optional).
  .highlight("content", "<strong>", "</strong>")
  .getResultAsMap()

result.documents.foreach { doc: Map[String, Any] =>
  println("id: " + doc("id"))
  println(doc("highlight")) // highlighted content is set as the "highlight" property
}

solr-scala-client expects that the unique key is "id". If your schema has the different field as the unique key, you can specify the unique key name as following:

val result = client.query("content: Scala")
  .id("documentId") // Specify the unique key name
  .fields("documentId")
  .highlight("content", "<strong>", "</strong>")
  .getResultAsMap()

Asynchronous API

solr-scala-client has also asynchronous API based on AsyncHttpCleint.

val client = new AsyncSolrClient("http://localhost:8983/solr")

// Register
client
  .register(Map("id" -> "005", "name" -> "ThinkPad X1 Carbon", "manu" -> "Lenovo"))
  .onComplete{
    case Success(x) => println("registered!")
    case Failure(t) => t.printStackTrace()
  }

// Query
client.query("name:%name%")
  .fields("id", "manu", "name")
  .facetFields("manu")
  .sortBy("id", Order.asc)
  .getResultAsMap(Map("name" -> "ThinkPad X201s"))
  .onComplete {
    case Success(x) => println(x)
    case Failure(t) => t.printStackTrace()
  }

See more example at AsyncSolrClientSample.scala.

Release Notes

0.0.24 - 10 Mar 2020

  • Include facetpivot in mapquery result

0.0.23 - 24 Feb 2020

  • Facet Pivot Fields support
  • Update dependent libraries

0.0.22 - 11 Dec 2019

  • Spatial parameters support

0.0.21 - 22 Jun 2019

  • Scala 2.13.0 support

0.0.20 - 13 Jan 2019

  • Scala 2.13.0-M5 support
  • Support specifying collection with transaction

0.0.19 - 4 Jun 2018

  • Add support for grouping and qTime in the response
  • Allow batch processing with a specific collection

0.0.18 - 15 Feb 2018

  • Fix response leaking bug

0.0.17 - 5 Dec 2017

  • Upgrade to SolrJ-7.1.0
  • Switch backend to OkHttp from async-http-client
  • Allow specifying collection name when building query
  • Add implementation of CloudSolrClient with and without authentication

0.0.16 - 18 Oct 2017

  • Upgrade Scala and async-http-client

0.0.15 - 22 Nov 2016

  • Scala 2.12 support and library updating

0.0.14 - 14 Aug 2016

  • Small refactoring

0.0.13 - 13 Aug 2016

  • Upgrade to SolrJ-6.1.0
  • Change group id and package name to com.github.takezoe
  • Publish to the Maven central repository

0.0.12 - 7 Feb 2015

  • Add QueryBuilderBase#fq()
  • Add QueryBuilderBase#setRequestHandler()
  • Add date facet
  • Support for streaming results

0.0.11 - 29 Mar 2014

  • Add SolrClient#shutdown()
  • QueryBuilder became immutable
  • Upgrade solrj version to 4.5.1

0.0.10 - 08 Feb 2014

  • Fix escaping in string literal.

0.0.9 - 18 Dec 2013

  • Bug fix

0.0.8 - 2 Aug 2013

  • Added recommendation search support.
  • Added rollback and withTransaction to SolrScalaClient.
  • Added Asynchronous API.

0.0.7 - 4 Apr 2013

  • Add build for Scala 2.10
  • Upgrade to SolrJ 4.2.0
  • Support highlighting

0.0.6 - 22 Jan 2013

  • Fixed some ExpressionParser bugs.

0.0.5 - 20 Nov 2012

  • ExpressionParser became pluggable and added GoogleExpressionParser as an optional implementation of ExpressionParser.
  • Converts the full-width space to the half-width space in the expression before calling ExpressionParser.
  • Introduced the SolrServer factory. Auth.basic moved to SolrServerFactory.basicAuth and SolrServerFactory.dummy for unit testing.

0.0.4 - 16 Sep 2012

  • Expanding expression to the Solr query by ?VAR_NAME? in SolrClient#query().
  • Bug fix

0.0.3 - 16 Aug 2012

  • Added case class support in update operations.
  • Added commit() method to SolrClient.

0.0.2 - 27 May 2012

  • Added initializer which configures SolrClient.
  • Added basic authentication support as initializer.
  • Added facet search support.
  • Added case class support as query results and query parameters.

0.0.1 - 4 May 2012

  • Initial public release.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].