Git Product home page Git Product logo

Comments (5)

zjgreen avatar zjgreen commented on August 15, 2024 1

Hi @fulmicoton,

It makes sense what you say about treating = the same as (spaces) if I wrap it in quotes.

I think I'm able to reproduce what I didn't understand, though, sorry in advance if it ends up being some elementary encoding issue!

  1. Copy tantivy binary to a directory, and mkdir index

  2. Create new index

$ ./tantivy new -i index/

Creating new index
Let's define it's schema!



New field name  ? text
Text or unsigned 32-bit integer (T/I) ? t
Should the field be stored (Y/N) ? n
Should the field be indexed (Y/N) ? y
Should the field be tokenized (Y/N) ? y
Should the term frequencies (per doc) be in the index (Y/N) ? y
Should the term positions (per doc) be in the index (Y/N) ? y
Add another field (Y/N) ? y



New field name  ? name
Text or unsigned 32-bit integer (T/I) ? t
Should the field be stored (Y/N) ? y
Should the field be indexed (Y/N) ? n
Add another field (Y/N) ? n

[
  {
    "name": "text",
    "type": "text",
    "options": {
      "indexing": "position",
      "stored": false
    }
  },
  {
    "name": "name",
    "type": "text",
    "options": {
      "indexing": "unindexed",
      "stored": true
    }
  }
]
  1. Add a key="value" text to index
$ echo '{"name":"raul","text":"i am phrase=\"value\""}' | ./tantivy index -i index/
Commit succeed, docstamp at 1
Waiting for merging threads
Terminated successfully!
  1. Add another document with different words between to not match the phrase
$ echo '{"name":"paul","text":"i am not a phrase with value"}' | ./tantivy index -i index/
Commit succeed, docstamp at 2
Waiting for merging threads
Terminated successfully!
  1. Serve the index
$ ./tantivy serve -i index/
listening on http://localhost:3000

Attempts to isolate the first document which contains phrase="value"

Attempt 1

$ ./tantivy search -i index/ -q '"phrase=\"value\""'
{"name":["raul"]}
{"name":["paul"]}

Attempt 2

$ ./tantivy search -i index/ -q '"phrase=\\"value\\""'
{"name":["raul"]}
{"name":["paul"]}

Attempt 3

$ ./tantivy search -i index/ -q '"phrase=\\\"value\\\""'
{"name":["raul"]}
{"name":["paul"]}

(pause to laugh at https://xkcd.com/1638/)

Attempt 4

$ curl "http://localhost:3000/api/?q=%22phrase%3D%5C%22value%5C%22%22"
{
  "q": "\"phrase=\\\"value\\\"\"",
  "num_hits": 2,
  "hits": [
    {
      "doc": {
        "name": [
          "raul"
        ]
      }
    },
    {
      "doc": {
        "name": [
          "paul"
        ]
      }
    }
  ],

Attempt 5 - If i replace =," with spaces, it returns the one document

$ ./tantivy search -i index/ -q '"phrase value"'
{"name":["raul"]}


$ curl "http://localhost:3000/api/?q=%22phrase%20value%22"
{
  "q": "\"phrase value\"",
  "num_hits": 1,
  "hits": [
    {
      "doc": {
        "name": [
          "raul"
        ]
      }
    }
  ],

from tantivy-cli.

fulmicoton avatar fulmicoton commented on August 15, 2024

= signs are treated as a whitespace both by the analyzer and the
QueryParser.
Also by default the QueryParser treats sequence of tokens as
disjunctions, so your query is logically equivalent to name OR anonymous.

To get the result you expect you need to add quotation marks around your
query to declare it as a PhraseQuery.

Note it would then still match a doc that contains a space in place of the
equal. This problem cannot be solved without using a custom analyzer.

Finally, if you are performance critical there is also plenty of room to
make your use case run much faster.

from tantivy-cli.

zjgreen avatar zjgreen commented on August 15, 2024

Thanks @fulmicoton. That makes sense. I've found that some queries with special characters work as expected (with phrase matching) in CLI, but can not be properly escaped using the serve API.

For now I've just replaced them with a (space) and seems to do the trick.

Thanks!

from tantivy-cli.

fulmicoton avatar fulmicoton commented on August 15, 2024

That's surprising. In your response payload repeats the query. In your example the = sign was decoded correctly. If you add double quotation marks in your query you don't get the result you expect?

from tantivy-cli.

fulmicoton avatar fulmicoton commented on August 15, 2024

Thanks for the great bug report. I'll have a look at that soonish!

from tantivy-cli.

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.