Comments (4)
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.
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.
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.
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)
- Concurrency Search HOT 5
- Resolved: help changing operators HOT 7
- LockError on Windows HOT 1
- Please help Matt sync up the repos HOT 6
- Not possible to boost word adjacency in search results
- Current state of this project HOT 10
- Please do a release HOT 1
- Filtering Raising AttributeError only sometimes HOT 1
- can we have proximity within strict phrases?
- is literal HOT 1
- Invalid repo referenced in readme HOT 2
- TimeLimitCollector breaks filter of underlying FilterCollector
- 2.7.4: sphinx errors HOT 3
- 2.7.4: pytest error and warnings HOT 1
- 2.7.4: sphinx warnings `reference target not found`
- NestedParent query missing valid result
- NestedParent query is missing valid results HOT 1
- is there a way to add custom variations?
- <Schema: ['content']> is not a Schema
- Is AsyncWriter reliable to use?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from whoosh.