Identifying most popular documents

Posted on 2004-11-19
Last Modified: 2013-12-18
I'm not sure if this is possible or not, but I'll ask the question anyway......

I'd like to identify the most popular documents in a Lotus Notes database (i.e. those which are viewed the most frequently).
I guess it would be nice to have a counter on each document to identify the number of 'hits'.

Is this at all possible?

Question by:mrt1
    LVL 19

    Expert Comment

    for that u need to change the form. And add a new field. Update this field with increments of "1" and u can have what u are asking.
    LVL 15

    Expert Comment

    That would imply that everybody has editor access, maddy, so not a good solution.

    You will have to develop this :
    - Notes Client : in QueryOpen event, write a value to an existing document (for instance a profile document) or a separate, new Log document.  Then count the log documents :-)
    - Web : use the same technique in a QueryOpen agent (so use Lotusscript libraries) to do the same logging.  

    If it's a pure web application, you have more options, for instance by always using a servlet to access the documents (let the servlet count who accesses what), but it's not so clear what to do in the Notes client then.  Advantage here would be you could use it over several databases....


    LVL 19

    Expert Comment

    I implement this wit the help of a public access agent. In every document, I put a that calls an agent passing it necessary parameters. The agent then, with the help of passed parameters, increments the hit count of each document, which is stored separately.

    Storing the hit count is much more neat. Besides, if you want to analyze the hit counts (for reporting etc), if you have it at one place, it is fast to access.
    LVL 2

    Author Comment

    Thanks for the responses so far.....all my users have at least edit access, so I'm going for the 'quick and dirty' solution:

    Sub Postopen(Source As Notesuidocument)
          On Error Resume Next
          'Update the counter field
          Source.EditMode = True
          Call Source.FieldSetText("Documentation_Counter",Str(Source.FieldGetText("Documentation_Counter") + 1))
    End Sub

    The problem I have is that this leaves my document in edit mode, which I don't want. I've tried setting it back using Source.EditMode = False, but this puts me in recursive loop (i.e. changing the edit mode to false seems to fire the PostOpen event again).
    Is there an easy way around this?
    LVL 9

    Expert Comment

    There's another way, mrt1, though it's a little bit more complicated.

    Create another form as a hit counter. For the sake of this discussion, we'll call it Counter. (Actually, you don't need a form for it, as they'll never be directly viewed.)

    Create a view to view the documents based on having "Counter" as the "Form" field. For this discussion, call it (Counters). Have the first column display the "Key" field and the second column display the "Count" field.

    In your QueryOpen code on your main form, include this code:

    '==== BEGIN PASTE ====
    Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
          Dim doc As NotesDocument
          Dim cDoc As NotesDocument
          Dim db As NotesDatabase
          Dim view As NotesView
          Set doc = Source.Document
          Set db = doc.ParentDatabase
          Set view = db.GetView("(Counters)")
          Set cDoc = view.GetDocumentByKey(doc.UniversalID)
          If (cDoc Is Nothing) Then
                ' There was no counter document yet. Create one.
                Set cDoc = New NotesDocument(db)
                cDoc.Form = "Counter"
                cDoc.Key = doc.UniversalID
                cDoc.Count = 1
                Call cDoc.Save(True, False)
                ' There was a counter document. Increment it.
                cDoc.Count = cDoc.Count(0) + 1
                Call cDoc.Save(True, False)
          End If
          Print "This record has been opened" & Str$(cDoc.Count(0)) & " times."
    End Sub
    '===== END PASTE =====

    This will put a count in the information line at the bottom of the client when you open the document.

    Or, you can remove the Print line from the script and put a Computed For Display field on the other forms:

    @DbLookup("Notes": "NoCache"; ""; "(Counters)"; @Text(@DocUniqueID); 2)

    This way, the users who view the documents you're counting never have to edit the documents, which means any other audit-trail-type information you may need for those documents is not muddled with records of people merely looking at the document.

    It also means you can have counters for documents that people don't have the authority to edit directly.

    -- b.r.t.
    LVL 31

    Accepted Solution

    This one has been discussed to death in a number of other questions.

    The quickl and dirty approach has two major flaws: 1) edit access (you say is no problem), and 2) replication conflicts, which WILL occur if you have multipe  servers, and CAN occur even if not:
        user 1 open doc
        code runs on user 1's clients to update count
        user 1 goes into edit mode
        user 1 begins five minutes worth of editing
        meantime, user two opens doc
        code runs on user 2's client to update count
        user 1 hits save
        user 1's Notes recognizes that the document changes since user 1 opened it (user 2's count update)
        Notes asks user Yes/No to save as conflict doc

    The profile doc has three flaws
        again, users need access
        they are cached in the user session, so the count will not be accurate (simultaneous update or multiple updates from multiple users)
        you can't see the update count alongside the document in the view

    The non-profile central document has four flaws
        again, users need access -- you can have a separate DB for this
        you can get replication conflicts in the profile document!
        you can't see the update count alongside the document in the view

    I prefer the "generate a log entry per access" aproach.  You need a separate database for the logging that all users have depositor access to, or author access with create document.  The most efficient way to gen the documents is with the NotesLog class.  There are three flaws to this method:
        you can't see the update count alongside the document in the view
        to piece together statistics, you need to count the number of log documents (categorization makes this easier, though)
        you have to maintain an extra database
    The actual logging is quick, as NotesLog very efficiently opens a DB, deposits a doc, and closes it.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
    Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now