1

First i add documents to index like this:

writer.add_document(title=doc_path.split(os.sep)[-1], path=doc_path, content=text, textdata=text)

And then i just need to delete one of them completely from index by it's path. Documentation says there are few no low level method to do this:

delete_by_term(fieldname, termtext)

Deletes any documents where the given (indexed) field contains the given term. This is mostly useful for ID or KEYWORD fields.

delete_by_query(query)

Deletes any documents that match the given query.

but i can't find suitable and very convenient method for me where i can specify path of the document and just remove it. There is some low level method where i can specify internal doc_number, which i supposed to get somehow. Can anyone give me advice how it's better to accomplish this task?

Dmitrii
  • 604
  • 2
  • 9
  • 30

1 Answers1

0
ix = open_dir('/my_index_dir_path/..')
writer = ix.writer()
writer.delete_by_term('path', doc_path)
writer.commit()

delete_by_term

method does exactly what i need. Note, that first argument is a text string 'path', and them goes the actual path. My mistake was to put an actual path instead of attribute name.

Dmitrii
  • 604
  • 2
  • 9
  • 30
  • 1
    It's always better to add some explanation to the answer. Please edit it and improve your answer. – DaFois May 29 '19 at 10:37