Giter Club home page Giter Club logo

amazing-cloud-search's Introduction

Amazing Cloud Search - C# API For Amazon Cloud Search

Allow you to search, faceted search, add, update, remove objects from your Amazon Cloud Search Index in C#.

Improve Amazing Cloud Search !

Feel free to fork and improuve Amazing Cloud Search API.

Thanks to uWorkin for this work

I find work with uWorkin an awsome Melbourne based company using incredible technology. We chose to use Amazon Cloud Seach for it's powerfull search engine mechanism and specially for it's incredible faceleted search.

All my thanks to uWorkin who gave me the opportunity to work on and open source the first Amazon Cloud Search API for the C# community. http://www.uworkin.com

How to use

First you need a Amazon cloud search instance and it's URL (We will call it a key) It should look like : yourDomainName-xxxxxxxxxxxxx.us-east-1.cloudsearch.amazonaws.com

This exemple can be used with the IMDB default index that you can select when creating your Cloud Search.

It indexes movies which implement SearchDocument (just an ID):

public class Movie : SearchDocument
{
	public List<string> actor { get; set; }
	public string director { get; set; }
	public DateTime mydate { get; set; }
	public string title { get; set; }
	public int year { get; set; }
}

The reason why my object field starts in lowercase is because YOU NEED to match the field name in your index. This needs to be improved (feel free)

Add a movie

var cloudSearch = new CloudSearch<Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");
var movie = new Movie { id = "fjuhewdijsdjoi", title = "simple title", year = 2012, mydate = DateTime.Now, actor = new List<string> { "good actor1", "good actor2" }, director = "martin magakian" };
cloudSearch.Add(movie);

Remove a movie

var movie = new Movie { id = "fjuhewdijsdjoi" }
cloudSearch.Delete(movie);

Update a movie

movie.title = "In the skin of Amazon cloud search";
cloudSearch.Update(movie);

Search for movies

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars"};
var found = cloudSearch.Search(searchQuery);

Search for a maximum of 25 movies only in the category from Sci-Fi

var bQuery = new BooleanQuery();
var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
bQuery.Conditions.Add(gCondition);

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Size = 25, BooleanQuery = bQuery};
var found = cloudSearch.Search(searchQuery);

Search for movies only from 2000 to 2004 in category Sci-Fi

var bQuery = new BooleanQuery();
var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
var yCondition = new IntBooleanCondition("year");
yCondition.SetInterval(2000,2004);
bQuery.Conditions.Add(gCondition);
bQuery.Conditions.Add(yCondition);

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Facets = liFacet, Size = 20, BooleanQuery = bQuery};
var found = cloudSearch.Search(searchQuery);

Search for movies + number of result per category (faceted search)

var genreFacet = new Facet { Name = "genre" };
var liFacet = new List<Facet> { genreFacet };

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars"};
var found = cloudSearch.Search(searchQuery);

Search for movies + number of result in 'Sci-Fi' and 'Fantasy' category (faceted search)

var genreFacetContraint = new StringFacetConstraints();
genreFacetContraint.AddContraint("Sci-Fi");
genreFacetContraint.AddContraint("Fantasy");
var genreFacet = new Facet { Name = "genre", FacetContraint = genreFacetContraint };
var liFacet = new List<Facet> { genreFacet };

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Facets = liFacet};
var found = cloudSearch.Search(searchQuery);

Search for movies + number of results in the 'Sci-Fi' and 'Fantasy' categories + the number of result in the year 1950 and between 1980 and 2012 (faceted search)

var genreFacetContraint = new StringFacetConstraints();
genreFacetContraint.AddContraint("Sci-Fi");
genreFacetContraint.AddContraint("Fantasy");
var genreFacet = new Facet { Name = "genre", FacetContraint = genreFacetContraint };

var yearFacetContraint = new IntFacetContraints();
yearFacetContraint.AddFrom(1950);
yearFacetContraint.AddInterval(1980, 2012);
var yearFacet = new Facet { Name = "year", FacetContraint = yearFacetContraint };

var liFacet = new List<Facet> { genreFacet, yearFacet };

var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Facets = liFacet};
var found = cloudSearch.Search(searchQuery);

All together now: Facet for Sci-Fi,Fantasy, in 1950, between 1980 to 2012 + search only for movies in Sci-Fi from 2000 to 2004

var cloudSearch = new CloudSearch<Movie>("YOUR_CLOUD_SEARCH_API", "2011-02-01");

//build facet
var genreFacetContraint = new StringFacetConstraints();
genreFacetContraint.AddContraint("Sci-Fi");
genreFacetContraint.AddContraint("Fantasy");
var genreFacet = new Facet { Name = "genre", FacetContraint = genreFacetContraint };

var yearFacetContraint = new IntFacetContraints();
yearFacetContraint.AddFrom(1950);
yearFacetContraint.AddInterval(1980, 2012);
var yearFacet = new Facet { Name = "year", FacetContraint = yearFacetContraint };

var liFacet = new List<Facet> { genreFacet, yearFacet };


//build boolean query
var bQuery = new BooleanQuery();
var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
var yCondition = new IntBooleanCondition("year");
yCondition.SetInterval(2000,2004);
bQuery.Conditions.Add(gCondition);
bQuery.Conditions.Add(yCondition);

//build search
var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Facets = liFacet, Size = 20, BooleanQuery = bQuery};

//search
var found = cloudSearch.Search(searchQuery);

More option

Pagination

SearchQuery accepts parameter Size for the number of results. But also accepts a parameter Start which can by used for paginating the results. The total number of results is also displayed in the search results: found.hits.found

Limit top facet result

You can also request the top facet as part of the results. Facet object accepts a TopResult parameter. For exemple we want the top 3 movie genres of our search var genreFacet = new Facet { Name = "genre", TopResult = 2};

Dependency

  • Json.NET

Contact

Developed by Martin Magakian [email protected]

License

MIT License (MIT)

amazing-cloud-search's People

Contributors

bbehrens avatar garylcoxjr avatar ohthataaronbrown avatar chadmyers avatar

Watchers

 avatar Dru Sellers avatar  avatar Sam Tyson avatar Rex Morgan avatar Gary Sherman avatar  avatar Nathan Shilling avatar augsburg50 avatar Matt Smith avatar James Cloos avatar  avatar Blake Reinhart avatar  avatar  avatar  avatar Eric Wallace avatar Kathy avatar  avatar  avatar Aaron M Nessim avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.