Git Product home page Git Product logo

Comments (4)

fortable1999 avatar fortable1999 commented on July 17, 2024

Original comment by Stavros Korokithakis (Bitbucket: Stavros, GitHub: Stavros).


Oh, thanks for that, I didn't undestand exactly why that field was needed... You might want to clarify this a bit in the documentation, just to save people from having the same question in the future...

Thanks for your help!

from whoosh.

fortable1999 avatar fortable1999 commented on July 17, 2024

Original comment by Matt Chaput (Bitbucket: mchaput, GitHub: mchaput).


In the schema, I specified the field as the whoosh.fields.ID class, which indexes the full, exact contents of the field as a single "term" (that is, it does not break the field contents into individual words, convert it to lowercase, or do anything else before indexing). So only the exact URL would match.

Of course, deleting by prefix is sometimes a desirable feature. You could use the delete_by_query method with a Prefix query if you did want to delete all documents whose URLs start with a certain domain, e.g.:

from whoosh.query import Prefix

# Delete all documents containing
# a term in the "url" field starting with "http://mydomain/"

myindex.delete_by_query(Prefix("url", u"http://mydomain/"))
myindex.commit()

from whoosh.

fortable1999 avatar fortable1999 commented on July 17, 2024

Original comment by Stavros Korokithakis (Bitbucket: Stavros, GitHub: Stavros).


That does help indeed, thank you! One question, if I have, say, a URL field to identify the documents, wouldn't searching for "http://mydomain" also match "http://mydomain/directory"? Should I add a field with an md5 hash or something equivalent in order to do this correctly?

from whoosh.

fortable1999 avatar fortable1999 commented on July 17, 2024

Original comment by Matt Chaput (Bitbucket: mchaput, GitHub: mchaput).


Short answer: your schema should include one or more indexed fields that uniquely identify documents; Whoosh does not provide persistent document IDs automatically.

The delete_by_query(query) and delete_by_term(fieldname, text) methods on the Index and Writer objects let you delete documents that match a certain query or contain a certain term.

Whoosh does not assign an immutable ID to documents. (In some parts of the API you refer to documents by their document number, but that number can change when the index is optimized.) Usually you will have an indexed field whose contents uniquely identifies each document.

For example, in the Houdini documentation, the "path" field contains the unique path for each help page:

schema = fields.Schema(content=fields.TEXT,
                       title=fields.TEXT(stored=True),
                       path=fields.ID(stored=True),
                       ...

So when I update the index, I can delete documents using the path field. For example:

writer = myindex.writer()
for path in deletedpaths:
    writer.delete_by_term("path", path)
writer.commit()

Hope this helps!

from whoosh.

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.