Exemplo n.º 1
0
	void PhraseScorer::explain(int32_t _doc, Explanation* tfExplanation) {
		while (next() && doc() < _doc){
		}

		float_t phraseFreq = (doc() == _doc) ? freq : 0.0f;
		tfExplanation->setValue(getSimilarity()->tf(phraseFreq));

		StringBuffer buf;
		buf.append(_T("tf(phraseFreq="));
		buf.appendFloat(phraseFreq,2);
		buf.append(_T(")"));
		tfExplanation->setDescription(buf.getBuffer());
	}
Exemplo n.º 2
0
///todo: mem leaks
TCHAR* Explanation::toString(int32_t depth) {
 StringBuffer buffer;
 for (int32_t i = 0; i < depth; i++) {
   buffer.append(_T("  "));
 }
 buffer.appendFloat(getValue(),2);
 buffer.append(_T(" = "));
 buffer.append(getDescription());
 buffer.append(_T("\n"));

 for ( uint32_t j=0;j<details.size();j++ ){
   TCHAR* tmp = details[j]->toString(depth+1);
   buffer.append(tmp);
   _CLDELETE_CARRAY(tmp);
 }
 return buffer.toString();
}
Exemplo n.º 3
0
 /** Prints a user-readable version of this query. */
 TCHAR* RangeQuery::toString(const TCHAR* field) const
 {
     StringBuffer buffer;
     if ( field==NULL || _tcscmp(getField(),field)!=0 )
     {
         buffer.append( getField() );
         buffer.append( _T(":"));
     }
     buffer.append(inclusive ? _T("[") : _T("{"));
     buffer.append(lowerTerm != NULL ? lowerTerm->text() : _T("NULL"));
     buffer.append(_T(" TO "));
     buffer.append(upperTerm != NULL ? upperTerm->text() : _T("NULL"));
     buffer.append(inclusive ? _T("]") : _T("}"));
     if (getBoost() != 1.0f)
     {
         buffer.append( _T("^"));
         buffer.appendFloat( getBoost(),1 );
     }
     return buffer.toString();
 }
Exemplo n.º 4
0
///todo: mem leaks
TCHAR* Explanation::toHtml() {
 StringBuffer buffer;
 TCHAR* tmp;
 buffer.append(_T("<ul>\n"));

 buffer.append(_T("<li>"));
 buffer.appendFloat(getValue(),2);
 buffer.append(_T(" = "));
 
 buffer.append(getDescription());
 buffer.append(_T("</li>\n"));

 for ( uint32_t i=0;i<details.size();i++ ){
   tmp = details[i]->toHtml();
    buffer.append(tmp);
    _CLDELETE_CARRAY(tmp);
 }
 buffer.append(_T("</ul>\n"));

 return buffer.toString();
}
UChar *BooleanQuery::toString(const UChar *field) const
{
	StringBuffer buffer;
	if (getBoost() != 1.0) {
		buffer.append(_T("("));
	}

	UChar *buf;
	BooleanClause* c;
	bool isBooleanQuery;
	size_t size = clauses.size();
	for (uint32_t i = 0 ; i < size; i++) {
		c = clauses[i];
		isBooleanQuery = c->query->instanceOf(BooleanQuery::getClassName());

		if (c->required) // AND clause
			buffer.append(_T("+"));
		else if (c->prohibited) // NOT clause
			buffer.append(_T("-"));

		if (isBooleanQuery) // wrap sub-bools in parens
			buffer.append(_T("("));

		buf = c->query->toString(field);
		buffer.append(buf);
		_CLDELETE_CARRAY(buf);

		if (isBooleanQuery) // wrap sub-bools in parens
			buffer.append(_T(")"));

		if (i != size - 1)
			buffer.append(_T(" "));

		if (getBoost() != 1.0) {
			buffer.append(_T(")^"));
			buffer.appendFloat(getBoost(), 1);
		}
	}
	return buffer.toString();
}
Exemplo n.º 6
0
  TCHAR* BooleanQuery::toString(const TCHAR* field) const{
    StringBuffer buffer;
    if (getBoost() != 1.0) {
      buffer.append(_T("("));
    }

    for (uint32_t i = 0 ; i < clauses.size(); i++) {
      BooleanClause* c = clauses[i];
      if (c->prohibited)
        buffer.append(_T("-"));
      else if (c->required)
        buffer.append(_T("+"));

      if ( c->query->instanceOf(BooleanQuery::getClassName()) ) {	  // wrap sub-bools in parens
        buffer.append(_T("("));

        TCHAR* buf = c->query->toString(field);
        buffer.append(buf);
        _CLDELETE_CARRAY( buf );

        buffer.append(_T(")"));
      } else {
        TCHAR* buf = c->query->toString(field);
        buffer.append(buf);
        _CLDELETE_CARRAY( buf );
      }
      if (i != clauses.size()-1)
        buffer.append(_T(" "));

      if (getBoost() != 1.0) {
         buffer.append(_T(")^"));
         buffer.appendFloat(getBoost(),1);
      }
    }
    return buffer.toString();
  }