If I write and algorithm that performs a search using Lucene how can I state the computational complexity of it? I know that Lucene uses tf*idf scoring but I don’t know how it is implemented. I’ve found that tf*idf has the following complexity:
O(|D|+|T|)
where D is the set of documents and T the set of all terms.
However, I need someone who could check if this is correct and explain me why.
Thank you
Lucene basically uses a
Vector Space Model(VSM) with atf-idfscheme. So, in the standard setting we have:We determine the
Kdocuments of the collection with the highest vector space scores on the queryq. Typically, we seek these K top documents ordered by score in decreasing order; for instance many search engines use K = 10 to retrieve and rank-order the first page of the ten best results.The basic algorithm for computing vector space scores is:
Where
Lengthholds the lengths (normalization factors) for each of theNdocuments, whereas the array
Scoresholds the scores for each of the documents.tfis the term frequency of a term in a document.w(t,q)is the weight of the submitted query for a given term. Note that query is treated as abag of wordsand the vector of weights can be considered (as if it was another document).wf(d,q)is the logarithmic term weighting for query and documentAs described here: Complexity of vector dot-product, vector dot-product is
O(n). Here the dimension is the number of terms in our vocabulary:|T|, whereTis the set of terms.So, the time complexity of this algorithm is:
we consider |Q| fixed, where
Qis the set of words in the query (which average size is low, in average a query has between 2 and 3 terms) andDis the set of all documents.However, for a search, these sets are bounded and indexes don’t tend to grow very often. So, as a result, searches using VSM are really fast (when
TandDare large the search is really slow and one has to find an alternative approach).