![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Soulmate is a tool to help solve the common problem of developing a fast autocomplete feature. It uses Redis's sorted sets to build an index of partially completed words and the corresponding top matching items, and provides a simple sinatra app to query them. Soulmate finishes your sentences.
Soulmate was designed to be simple and fast, and offers the following:
An item is a simple JSON object that looks like:
{
"id": 3,
"term": "Citi Field",
"score": 81,
"data": {
"url": "/citi-field-tickets/",
"subtitle": "Flushing, NY"
}
}
Where id
is a unique identifier (within the specific type), term
is the phrase you wish to provide completions for, score
is a user-specified ranking metric (redis will order things lexicographically for items with the same score), and data
is an optional container for metadata you'd like to return when this item is matched (at SeatGeek we're including a url for the item as well as a subtitle for when we present it in an autocomplete dropdown).
See Soulmate in action at SeatGeek.
As always, kick things off with a gem install
:
gem install soulmate
You can load data into Soulmate by piping items in the JSON lines format into soulmate load TYPE
.
Here's a sample venues.json
(one JSON item per line):
{"id":1,"term":"Dodger Stadium","score":85,"data":{"url":"\/dodger-stadium-tickets\/","subtitle":"Los Angeles, CA"}}
{"id":28,"term":"Angel Stadium","score":85,"data":{"url":"\/angel-stadium-tickets\/","subtitle":"Anaheim, CA"}}
{"id":30,"term":"Chase Field ","score":85,"data":{"url":"\/chase-field-tickets\/","subtitle":"Phoenix, AZ"}}
{"id":29,"term":"Sun Life Stadium","score":84,"data":{"url":"\/sun-life-stadium-tickets\/","subtitle":"Miami, FL"}}
{"id":2,"term":"Turner Field","score":83,"data":{"url":"\/turner-field-tickets\/","subtitle":"Atlanta, GA"}}
And here's the load command (Soulmate assumes redis is running locally on the default port, or you can specify a redis connection string with the --redis
argument):
$ soulmate load venue --redis=redis://localhost:6379/0 < venues.json
You can also provide an array of strings under the aliases
key that will also be added to the index for this item.
Once it's loaded, we can query this data by starting soulmate-web
:
$ soulmate-web --foreground --no-launch --redis=redis://localhost:6379/0
And viewing the service in your browser: http://localhost:5678/search?types[]=venue&term=stad. You should see something like:
{
"term": "stad",
"results": {
"venue": [
{
"id": 28,
"term": "Angel Stadium",
"score": 85,
"data": {
"url": "/angel-stadium-tickets/",
"subtitle": "Anaheim, CA"
}
},
{
"id": 1,
"term": "Dodger Stadium",
"score": 85,
"data": {
"url": "/dodger-stadium-tickets/",
"subtitle": "Los Angeles, CA"
}
},
{
"id": 29,
"term": "Sun Life Stadium",
"score": 84,
"data": {
"url": "/sun-life-stadium-tickets/",
"subtitle": "Miami, FL"
}
}
]
}
}
The /search
method supports multiple types
as well as an optional limit
. For example: http://localhost:5678/search?types[]=event&types[]=venue&types[]=performer&limit=3&term=yank
. You can also add the callback
parameter to enable JSONP output.
If you are integrating Soulmate into a rails app, an alternative to launching a separate 'soulmate-web' server is to mount the sinatra app inside of rails.
Add this to routes.rb:
mount Soulmate::Server, :at => "/sm"
Add this to gemfile:
gem 'rack-contrib'
gem 'soulmate', :require => 'soulmate/server'
Then you can query soulmate at the /sm url, for example: http://localhost:3000/sm/search?types[]=venues&limit=6&term=kitten
You can also config your redis instance:
# config/initializers/soulmate.rb
Soulmate.redis = 'redis://127.0.0.1:6379/0'
# or you can asign an existing instance of Redis, Redis::Namespace, etc.
# Soulmate.redis = $redis
Soulmate doesn't include any client-side code necessary to render an autocompleter, but Mitch Crowe put together a pretty cool looking jquery plugin designed for exactly that: soulmate.js.
Copyright (c) 2011 Eric Waller. See LICENSE.txt for further details.
FAQs
Unknown package
We found that soulmate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.