Giter VIP home page Giter VIP logo

instantsearch-ios-examples's Introduction

Warning: Migrated

InstantSearch Examples has been migrated to the main InstantSearch repository. The updated Examples project is available in the dedicated directory. This repository is no longer supported, please create your issues and submit your contributions to the main InstantSearch repository.

InstantSearch iOS: Examples

Example of search experience components built with algolia/instantsearch-ios.

InstantSearch iOS is a library providing components and helpers to help you build the best instant-search experience on iOS with Algolia. It is built on top of Algolia's Swift API Client to provide you a high-level solution to quickly build various search interfaces.

Examples

We have built a demo application to give you an idea of what you can build with InstantSearch iOS:

Search as you type experience

  • Search results updated on each keystroke



















Single index search

  • Search as you type experience
  • Search a movie by title, actor or year
  • Infinite scrolling of search results



















Multi index search

Example of a multi-index search interface.

  • Multi-Index table showcasing results from different indices (movies and actors)
  • Uses the same index for movies as single index example, but presents results differently (horizontal scrolling)
  • Independent infinite scrolling for both hits views















Search for facets

Example of a facet search interface.

  • Search as you type experience
  • Presentation of selected facets


















Sorting results

Example of sorting movies by year attribute.






















Query Suggestions

Example of updating list of relevant queries that your users can select from as they type.

















instantsearch-ios-examples's People

Contributors

robertmogos avatar spinach avatar vladislavfitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instantsearch-ios-examples's Issues

Around Precision property has issue , when It assigned gives code 400 error

When I try to assign a property called aroundPrecision , Query Response throws an error with code 400

I checked by assigning as below
searcher.request.query.aroundPrecision = [.init(integerLiteral: 1000)]

Request of Query Would be
&aroundLatLng=23.0321,72.5252&aroundRadius=50000&aroundPrecision=%5B%7B%22from%22:0.0,%22value%22:1000.0%7D%5D

Response of Query Would be

{
  "message" : "Invalid value for \"aroundPrecision\" parameter, expected valid JSON (Expecting an integer (near 1:13))",
  "status" : 400
}

I would love to know the solution of above problem

Files Missing

ProductTableViewCell and ProductTableViewCell+ProductHit Files are missing in the main code

Demo build errors

With the current pod file cocoapods is unable to resolve dependancies. If I modify the podfile to remove the branches then the build fails.

RefinementList search controller

Testing the ecommerce example with iOS 10:

In the ecommerce app, the UISearchController created in the filter view controllers for type and categories) does not filter the list.
Is there something missing to connect it to search for facets?

If I use InstantSearch.shared.register(searchController: searchController) , it seems like it's filtering the records, not the facets.

HitsIteractor showItemsOnEmptyQuery not working.

Hi,

I have been implementing the new v5 of InstantSearch in my app and cannot seem to get the showItemsOnEmptyQuery parameter to make any difference.

Below is my setup:

class SearchViewController: UIViewController {
    
    let searcher: SingleIndexSearcher = SingleIndexSearcher(appID: "ID", apiKey: "AppKey", indexName: "IndexName")
    let queryInputInteractor: QueryInputInteractor = .init()
    var searchBarController: SearchBarController?

    var hitsInteractor: HitsInteractor<JSON> = .init(infiniteScrolling: .on(withOffset: 10), showItemsOnEmptyQuery: false)
    
    var results: [JSON] = []
    
    @IBOutlet var searchBar: UISearchBar!
    
    override func viewDidLoad() {
        // Init the controller with our search bar from storyboard.
        self.searchBarController = .init(searchBar: self.searchBar)

       // Notify searcher about query text changes and launch a new search
        queryInputInteractor.connectSearcher(searcher)

        // Update query text in interactor each time query text changed in a UISearchBar
        queryInputInteractor.connectController(self.searchBarController!)

        // Update hitsInteractor with up-to-date search results
        hitsInteractor.connectSearcher(searcher)
        hitsInteractor.onResultsUpdated.subscribe(with: self) { _, results in
          self.results = results.hits
          self.tableView.reloadData()
        }
   }

As you can see, I feed the UISearchBar from the Storyboard to the searchBarController and then leverage hitsInteractor.onResultsUpdated method to collect the results. So far, everything works fine and I am able to successfully retrieve the results.

However, when the search bar is empty, then onResultsUpdated returns all results, effectively ignoring the showItemsOnEmptyQuery: false parameter that was set during init.

Do you have any idea why the parameter is not being respected and how to prevent any results on empty query?

Thanks in advance.

How to access raw data once tableviewcell is clicked

In tableview we display limited data. We need to access the raw data for the hit on selecting the tableviewcell.

We have row id from selected tablecell, where can i find raw data from the resultset?

Something like, any hint where raw data is hold?

let rawHit = hits[selectedCellIndex]

None of the example has this defined as well.

Geo Search returns nothing on iOS

So I am working on migrating my geoSearch functionality from GeoFire to Algolia because there are more options as far as filtering, and many other things that could make life a heck of a lot easier.

I am currently using it to search for events nearest a users location. Just as the docs say (https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/) I have added this attribute

"_geoloc": {
"lat": 37.7909427,
"lng": -122.4084994
}

To make geosearching possible. Following that I use SwiftLocation to grab the users current latitude and longitude for my geo query/search. The docs say do something like this (https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLng/)

let query = Query(query: "query")
query.aroundLatLng = LatLng(lat: 40.71, lng: -74.01)

index.search(query, completionHandler: { (res, error) in
  print(res)
})

Which I accomplish with this block of code

static func fetchEventsFromAlgolia(completion: @escaping (String) -> Void) {
    
    let client = Client(appID: Algolia.appID, apiKey: Algolia.apiKey)
    let index = client.index(withName:indice.events)
    let query = Query(query: "query")

    LocationService.getUserLocation { (currentLocation) in
        
        guard let latitude = currentLocation?.coordinate.latitude else {
            completion("error finding latitude")
            return
        }
        
        guard let longitude = currentLocation?.coordinate.longitude else {
            completion("error finding longitude")
            return
        }
        
        query.aroundLatLng = LatLng(lat: latitude, lng:longitude )
        query.aroundRadius = .all
        index.search(query, completionHandler: { (res, err) in
            if err == nil {
                guard let res = res else {
                    completion("error with res unwrapping")
                    return
                }
                
                
                let data = res["hits"]! as! [NSDictionary]
                print("Result: \(data.count)")
                print(res.description)
                completion("success events should have been printed")
            }else {
                completion(err as! String)
            }
        })
        
        
    }
    
}

However when I print the results to the terminal I get nothing. It seems as though it successfully does the query but not results come back.

Here is what one of the event entries looks like in Algolia for my specific case

{
  "attend:count": 6,
  "event:category": "concert",
  "event:city": "San Francisco",
  "event:date": {
    "end:date": "05/11/2019",
    "end:time": "11:35 PM",
    "start:date": "04/19/2019",
    "start:time": "10:55 PM"
  },
  "event:datetime": {
    "end": 1557632100,
    "start": 1555728900
  },
  "event:description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
  "event:imageURL": "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2Flilpump.jpg?alt=media&token=40c310d2-fe1e-49c4-b3a6-7419e6ef7ddd",
  "event:name": "lil pump performance",
  "event:price": 0,
  "event:promo": "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FBEVT%2FTravis%20Scott_%20Houston%20Birds%20Eye%20View%20Tour%20Promo.mp4?alt=media&token=6d27d76e-281e-4083-a0ff-dbe2f25703e7",
  "event:state": "CA",
  "event:street:address": "2 Stockton St",
  "event:zip": 94108,
  "host_user": [
    "XwOBrK6zJXRG7wltV1QvoVXi6Jg1"
  ],
  "tags": [
    "hip hop",
    "concert"
  ],
  "_geoloc": {
    "lat": 37.7909427,
    "lng": -122.4084994
  },
  "objectID": "LPP"
}

If anyone can see where I went wrong please let me know!!!

Install InstantSearchClient via SPM

I am following this great tutorial:
https://medium.com/@soares.rfarias/how-to-set-up-firestore-and-algolia-319fcf2c0d37

The author installs InstantSearchClient via CocoaPods. On my case, I would like to use SPM but didn't find InstantSearchClient package, only InstantSearch.

When I install InstantSearch via SPM, the code bellow doesn't work so I guess I need to install InstantSearchClient?

import Foundation
import InstantSearchClient

class MyViewModel {
    
    var myObjects = [MyObject]()
    private var collectionIndex : Index!
    private let query = Query()
    
    init() {
        setupAlgoliaSearch()
    }
    
    private func setupAlgoliaSearch() {
        guard let bundle = Bundle.main.bundleIdentifier else { return }
        let searchClient = Client(appID: "", apiKey: "")
        let indexName = bundle == "YOUR_PRODUCTION_BUNDLE" ? "COLLECTION_prod" : "COLLECTION_dev"
        collectionIndex = searchClient.index(withName: indexName)
        query.hitsPerPage = 20
        
        // Limiting the attributes to be retrieved helps reduce response size and improve performance.
        query.attributesToRetrieve = ["property1", "property2", "property3"]
        query.attributesToHighlight = ["property1", "property2", "property3"]
    }
    
    func searchCollection(forText searchString : String) {
        query.query = searchString
        collectionIndex.search(query) { (content, error) in
            guard let content = content else {
                if let error = error {
                    print(error.localizedDescription)
                }
                return
            }
            
            guard let hits = content["hits"] as? [[String: AnyObject]] else { return }
            
            hits.forEach({ (record) in
                // ... handle record JSON.
                let myObject = MyObject(json: record)
                myObjects.append(myObject)
            })
        }
    }
}

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.