Git Product home page Git Product logo

Comments (4)

jasonbosco avatar jasonbosco commented on July 24, 2024 2

I was able to replicate the issue with that. Thank you!

Turns out this is because Typesense server was returning invalid JSON:

{
    "message": "Could not find `y` in the infix index. Make sure to enable infix search by specifying `"infix ": true` in the schema."
}

Notice how the double quotes are not escaped properly. We'll fix this in Typesense Server shortly.

from typesense.

jasonbosco avatar jasonbosco commented on July 24, 2024

Hmmm, could you give me a JS snippet that reproduces the issue?

Here's a template to use: https://github.com/typesense/typesense-js/blob/master/doc/examples/server/search.js

from typesense.

rovaniemi avatar rovaniemi commented on July 24, 2024

@jasonbosco

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Typesense Browser Demo</title>
</head>
<body>
<div>
    <h1>Typesense Browser Demo</h1>
    <div>
        <input id="search-input" type="text" placeholder="search terms"/>
        <button id="search-button" type="submit" onclick=search()>Search</button>
    </div>
    <pre id="search-results">
    </pre>
</div>
<script src="../../../dist/Typesense.js"></script>
<script>
  /*
   Setup: See clientInitalization.js for quick instructions on starting the Typesense server.
  */

  // Create a client
  // We're using Typesense.Client instead of Typesense.SearchClient just for the purposes of this example, so we can index using the same client
  // You'd typically want to use Typesense.SearchClient in the browser, if you only need to perform search operations
  var typesense = new Typesense.Client({
    'nodes': [
      {
        'host': 'localhost',
        'port': '8108',
        'protocol': 'http'
      }
    ],
    'apiKey': 'xyz',
    'numRetries': 3,
    'connectionTimeoutSeconds': 10,
    'retryIntervalSeconds': 0.1,
    'healthcheckIntervalSeconds': 2,
    'logLevel': 'debug'
  })
  
    let schema = {
    'name': 'x',
    'num_documents': 0,
    'fields': [
      {
        'name': 'y',
        'type': 'string'
      }
    ]
  }


  // create a collection, in case it doesn't exist
  //    We're creating a collection from the browser just for the purposes of this example.
  //    You'd typically create a collection server-side and only use the search endpoint from the browser.
  //    So you want to pass an API key that only allows searches in the api-key field, instead of the master key when using this library in a browser.
  //    See keys.js in docs/examples/server/keys.js for an example of how to generate a search only API key.

  function search () {
    var searchTerm = document.getElementById('search-input').value
    typesense.collections('x').documents().search({
      'q': searchTerm,
      'query_by': 'y',
      'per_page': 10,
      'infix': 'always'
    }).then(function (searchResults) {
      document.getElementById('search-results').innerHTML = JSON.stringify(searchResults, null, 2)
    }).catch(function (error) {
      document.getElementById('search-results').innerHTML = error
    })
  }

</script>
</body>
</html>

This should repeat it. At least I managed to reproduce it locally. (However, I tested it on our environment, so I really don't know if that will be repeated in a completely empty collection.)

image

from typesense.

jasonbosco avatar jasonbosco commented on July 24, 2024

Fix is now available in 27.0.rc18

from typesense.

Related Issues (20)

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.