Example #1
0
/*
   This function will search all approximate occurrences of P in T.
   An occurrence is at j iff d_{ID}(P+t,T_{j'...j}) <= k for some j', t.
   We will only report minimal occurrences 
   (those that can not be derived from other (better) occurrences.
*/
occType* searchAllTranspositions(matchList *Mt, char *P, char *T, int m, int n, int k)
{
	int j, t;
	occType *occ = (occType*)malloc((n+1)*sizeof(occType));
      
	preProcessAllTranspositions(Mt, P,T,m,n);
	for (j=1; j<=n; j++)
	{
		occ[j].value = INT_MAX;
		occ[j].t = 0;
	}
    
	for (t=0;t<MAX_TRANSPOSITION;t++)
	{
		if (Mt[t].first->next == Mt[t].last) continue;
		searchOccurrences(m,k,t - MAX_TRANSPOSITION / 2,&(Mt[t]),occ);
	}
	cleanUp(Mt);
	return occ; /* returns the array occ[1...n] of occurrences */
}
Example #2
0
void SearchView::requestEnded(QNetworkReply *e)
{
    for(int i=0; i<mWidgets.count(); i++)
        mWidgets.at(i)->hide();
    mWidgets.clear();

    QDomDocument xml;
    if (xml.setContent(e->readAll()))
    {
        QDomElement root = xml.documentElement();
        QDomNodeList topLevel = root.childNodes();

        /* Google search */
        if (topLevel.count() > 0)
        {
            SearchViewTitle *titleGoogleSearch = new SearchViewTitle("Google Search", mWidget);
            mWidgets.push_back(titleGoogleSearch);

            mGoogleSearch.clear();
        }

        for(int i=0; i<topLevel.count(); i++)
        {
            QDomElement suggestion = topLevel.at(i).toElement();
            QDomNodeList nodes = suggestion.childNodes();
            for(int j=0; j<nodes.count(); j++)
            {
                QDomElement s = nodes.at(j).toElement();
                if (s.tagName() == "suggestion")
                {
                    SearchViewItem *it = new SearchViewItem(s.attribute("data"), mWidget);
                    mWidgets.push_back(it);
                    mGoogleSearch.push_back(s.attribute("data"));
                }
            }
        }
    }

    if (mGoogleSearch.count() > 0)
    {
        SearchViewSeparator *sepGoogleSearch = new SearchViewSeparator(mWidget);
        mWidgets.push_back(sepGoogleSearch);
    }

    /* Service */
    SearchViewTitle *titleService = new SearchViewTitle("Services", mWidget);
    mWidgets.push_back(titleService);

    for(int i=0; i<mServices.keys().count(); i++)
    {
        QString s = "\"";
        s += mWord;
        s += "\" on ";
        s += mServices.keys().at(i);

        SearchViewItem *it = new SearchViewItem(s, mWidget);
        mWidgets.push_back(it);
    }

    if (mWord.isEmpty())
    {
        this->organize();
        return;
    }

    if (Application::getWindow()->getWebContainer()->getWebView()->url().isLocalFile())
    {
        SearchViewSeparator *sepService = new SearchViewSeparator(mWidget);
        mWidgets.push_back(sepService);

        /* On this page */
        SearchViewTitle *titleOnThisPage = new SearchViewTitle("On this page", mWidget);
        mWidgets.push_back(titleOnThisPage);

        QString oc = mWord;
        oc += " (";
        oc += QString::number(searchOccurrences());
        oc += " results)";
        SearchViewItem *it = new SearchViewItem(oc, mWidget);
        mWidgets.push_back(it);
    }

    /*Application::getWindow()->getWebContainer()->getWebView()->findText("", QWebPage::HighlightAllOccurrences);
    Application::getWindow()->getWebContainer()->getWebView()->findText(mWord, QWebPage::HighlightAllOccurrences);
    for(int i=0; i<mOnThisPage.count(); i++)
    {
        SearchViewItem *it = new SearchViewItem(mOnThisPage.at(i), mWidget);
        mWidgets.push_back(it);
    }*/
    this->organize();
}