Hi Stephen thanks for subscribing and posting,

Your rationale was very good regarding adding the extra search field, the 
complete line would have to include the '__name' qualifier to avoid having 
the user inputting the id of the metadata type as you correctly inferred:

    {'name': u'documentmetadata__metadata_type__name', 'title': 
_(u'Metadata type')},

Every double underscore on Django means 'field' and it can go on several 
levels deep.  Root level is 'Document' model as defined at the beginning of 
the register function:

register('document', *Document*, _(u'document')

next level is '*documentmetadata*' field from the '*Document*' model which 
itself is a *foreign* *key field* to the '*DocumentMetadata*' model, next 
level is the '*metadata_type*' field of '*DocumentMetadata*' model which is 
a *foreign* *key field* to '*MetadataType*' model, and finally '*name*' *
field* from '*MetadataType*' Model, belonging to the *DocumentMetadata*record 
being found which itself belong to the '
*Document*' being returned in the search result :)  Tons of fun right?!  A 
full SDK and Mayan internals chapter for developers is in the TO DO list 
for the next version.

The development version of Mayan has already moved to a dedicated search 
solution using Haystack which allows for different search backends (Sphinx, 
Whoosh, etc) to be used and I believe some of those might support the type 
of search string queries (AND OR < > = ) you mentioned and the end.

--Roberto

On Monday, August 20, 2012 5:00:39 PM UTC-4, Stephen Knox wrote:
>
> Hi everyone,
>
> I am new to using Mayan and this mailing list, but I am happy to have 
> found something open source that really seems to meet my needs as a fairly 
> lightwight open-source DMS, and can use SQLite (I'm just doing this on my 
> local machine, so no real need for a complicated DB setup).
>
> I have started to upload documents, and thinking about customising etc. My 
> first thought was to have functionality to bulk-add tags, and I have 
> submitted a git enhancement ticket for that (
> https://github.com/rosarior/mayan/issues/31).
>
> The other thing that I thought might be a useful enhancement, at least for 
> my needs, was to be able to search only certain metadata fields. For 
> instance, if you had a metadata field 'Author' clearly it's useful to be 
> able to search for all documents with 'Dickens' as the author. As I 
> understand it, currently the metadata search just looks in the 
> metadata_documentmetadata table under the value field, so doesn't relate to 
> the metadata type. I know Python, but very new to Django, but I had a play 
> around with the source and eventually figured out that the lines to change 
> were at the bottom of the mayan/mayan/apps/documents/models.py file. I 
> registered various combinations of new fields trying to get the field to 
> search on the foreign key in the metadata_metadatatype table. 
>
> This included adding 
>
> "{'name': u'metadatatype__name', 'title': _(u'Metadata type')},
>
> to that file, which I thought would enable search on the metadatatype. 
> However, I kept getting the message 
>
> "Cannot resolve keyword u'metadatatype' into field. Choices are: comments, 
> date_added, description, document_type, documentcheckout, documentmetadata, 
> documentrenamecount, documentversion, folderdocument, id, 
> indexinstancenode, queuedocument, recentdocument, tagged_items, tags, uuid"
>
> I assume these names related somehow to the document class/app somehow but 
> wasn't sure how. 
>
> I was able to make it work by adding:
>
> "{'name': u'documentmetadata__metadata_type', 'title': _(u'Metadata 
> type')},
>
> and changing the comparison type to 'exact', but obviously this isn't 
> really a solution as it relies on the user knowing the metadatatype id, 
> rather than the name.
>
> So, given that I've got fairly hopelessly lost, can anyone explain what I 
> was doing wrong, or why what I was trying to do is impossible? I guessed 
> something to do with joining tables but my inexperience is showing.
>
> Essentially what I was looking for was something that could some something 
> like the following SQL, which works:
>
> select * from metadata_documentmetadata 
> where metadata_type_id = (select id from metadata_metadatatype where name 
> = 'Author') 
> and value like '%Dickens%'
>
> In addition, is there a wider context to this, i.e. is this something that 
> has been tried / thought about before, from a functionality or UI point of 
> view? Perhaps the consensus is that it isn't even necessary? What would be 
> even better would be the option to search for metadata in several fields, 
> i.e. author = 'Charles Dickens' and date < 1880.
>
> Any thoughts or pointers welcome.
>
> Regards
>
> Stephen Knox
>

-- 



Reply via email to