fogbound.net




Page 10 of 55« First...89101112...2030...Last »

Tue, 12 Jun 2012

Spelling Suggestions from Solr using Yii-solr

— SjG @ 7:48 pm

So a Yii app wants to query Solr using the Yii-solr extension, and wants to provide spelling suggestions for the provided search term. We need the suggestions to be unique, i.e., no repeated suggesttions, and we don’t want negative suggestions, i.e., if the user’s search wanted to exclude “foo”, we don’t want to suggest “foo” as a possible correction. There’s probably a better way to do all this, but I couldn’t figure it out. Here’s what I did instead (as always, forgive the code style/formatting):

I created a subclass of ASolrConnection that switches to using the “spell” Solr servlet:


class SolrSpellingConnection extends ASolrConnection {
public $servlet_type;
public $servlet_path;
public function resetClient()
{
parent::resetClient();
if (isset($this->servlet_type) && isset($this->servlet_path))
{
$this->_client->setServlet($this->servlet_type,$this->servlet_path);
}
}
}

This is instantiated in the app’s config file:

'solr' => array(
'class'=>'app.components.SolrSpellingConnection',
'clientOptions'=>array(
'hostname'=>'localhost',
'port'=>8983,
),
'servlet_type'=>SolrClient::SEARCH_SERVLET_TYPE,
'servlet_path'=>'spell'
),

Then, my Solr query data-provider looks something like:


$criteria = new ASolrCriteria;
$criteria->query = $queryterm;
$criteria->set('spellcheck','true');
$pages=array('pageSize'=>15);
$dataprovider = new ASolrDataProvider(ASolrDocument::model(),array('criteria'=>$criteria,'pagination'=>$pages));
return $dataprovider;

In my controller, I add some code to process the suggestions:

public function buildSuggestionList($dataprovider, $originalQueryString)
{
$suggestions = array();
$terms = array();
if ($dataprovider != null)
{
$facets = $dataprovider->getQueryFacets();
$resp = $dataprovider->getSolrQueryResponse()->getSolrObject();
if (isset($resp['spellcheck']))
{
if (isset($resp['spellcheck']['suggestions']))
{
foreach ($resp['spellcheck']['suggestions'] as $thisSuggest)
{
if (is_object($thisSuggest) && get_class($thisSuggest) == 'SolrObject')
{
if (isset($thisSuggest['suggestion']) && is_array($thisSuggest['suggestion']))
{
foreach($thisSuggest['suggestion'] as $thisTerm)
{
$terms[$thisTerm]=1;
}
}
}
}
}
}
}
foreach($terms as $termKey=>$val)
{
// Solr adds negated or added terms to suggestions if they don't match case
if (!preg_match('/\b'.$termKey.'\b/i',$originalQueryString))
{
$suggestions[] = CHtml::link($termKey,'/index.php/mysearchcontroller?q='.urlencode($termKey));
}
}
return $suggestions;
}

I can then display the main collection of results using a CWidget. For displaying suggestions, however, a bit of specific code is required:


$suggestions = $this->buildSuggestionList($dataprovider, $originalQueryString);
if (count($suggestions) > 0)
{
echo '<p>Did you mean '.implode(' or ',$suggestions).'?</p>';
}
?>

When this is all in place, you should get decent suggestions from Solr. Of course, you will need to have Solr build a spelling index! The easiest way to do that is simply connect to Solr’s web interface and tell it to build the index:

http://localhost:8983/solr/spell?spellcheck.build=true


Sun, 6 May 2012

My Fan Club

— SjG @ 3:20 pm

So the server that operates the security cameras at the house suddenly started making a nasty wheezy noise. The periodicity of the noise suggested a fan bearing going bad or running dry.

So I shut the machine down, and tore it apart. I disassembled and lubed the case- and power-supply fans. I put everything back together and fired up the machine, but the noise was still there. I tried to remove the CPU heat-sink fan, but it’s held in by plastic snappers, and I didn’t want to fight with them. In the end, I went on e-Bay and ordered replacement case- and power supply fans, along with a new CPU heat-sink / fan assembly.

The new stuff arrived Thursday, and I swapped out the old stuff. Then reassembled. The noise was still there. I started pulling my hair out.

Today, I was going to solve it, or die trying. I unplugged the hard drive and the CD drive. Still made the noise. I unplugged the case fan. Still made the noise. I unplugged the CPU heat-sink fan. Still made the noise. I physically moved the power supply away, while powering the chassis. At this point, there are no moving parts whatsoever within the chassis. Still noisy!

When I finally stopped punching the wall and kicking the cat, I leaned my head into the machine, and tried to find the source of the noise. And there it was. The crappy little graphics card’s heat sink has a fan in it, completely obscured from view. I pulled the card, tore it apart, and lubed the fan, and now, finally, the machine runs silently again.

I think if I ever rebuild the thing, it’s going to be 100% solid state.

Filed in:

Mon, 12 Mar 2012

Royal Flutter

— SjG @ 10:49 am

Well, now, over the weekend was the 10,0000th download of our Royal Flutter font from dafont.com (the original distribution site). Of course, any free font distributed on dafont.com is copied and distributed through dozens of other sites such as MaxFonts, FontRiver, FFonts, Fonts2U, WebToolHub, and more.

I wonder what percentage of the downloaders actually use the font. I know there are plenty of font collectors out there. It can be addictive, looking at all the type faces, and thinking “yes! I could use that some day!”

Work progresses on a new (commercial) font which will likely be called Lunatrix. It’s a techno/space font, and will be available in five weights. Something more for the collections!


Sat, 25 Feb 2012

Bad Business

— SjG @ 9:48 am

Now, I don’t shop at Target stores any more because they give campaign money to candidates who have regressive social agendas. However, being a realist, I know that it’s not always possible to live in modern society and remain pure to ideals. Instead of buying clothes at Target, I could buy them at Amazon, for example, but they have their own labor issues. So, despite my ethical concerns, I visited the Target web site.

Access Denied!
Are you f'n serious???

Yep. That’s right. They won’t even let you look at their site unless you accept their evil tracking cookies.
I guess it goes without saying that they failed to win me back.

(P.S. If you’re not running Ghostery, or the equivalent, you should be.)


Mon, 20 Feb 2012

Further Thoughts on Pomona College Dining Hall Workers

— SjG @ 11:52 am

The “Work Authorization Issue” has been rolling on in the media over the last few weeks, with stories appearing in the New York Times, Huffington Post, and San Jose Mercury News among other papers. In addition to the letter sent out by Pomona College President David Oxtoby (to which I previously posted my thoughts), there have been postings to Facebook by Jennifer Wilcox, the college’s Young Alumni Trustee, and, Friday, a new letter from Dodie Bump, the President of the Pomona College Alumni Association.

These communications have all struggled to represent the issues of work authorization and the dining hall workers’ unionization effort as entirely separate issues. This last letter from Bump, for example, argues that the timing of the work authorization issue and the unionization effort “was truly a tragic coincidence,” and that “as an anti-union tactic, this would have been pretty stupid.” I don’t think anyone is arguing that a union-busting move like this would be especially clever — Machiavellian, perhaps, or pragmatic, depending upon your views. In any case, let’s give the College the benefit of the doubt for a moment, and discuss the question: what would lead the College to get into a situation where such a “tragic coincidence” could occur?

We need to start by being honest. The College has been unequivocally against the unionization effort1. President Oxtoby has publicly criticized the idea in a letter to the school. The College has had to settle a complaint with the NLRB over practices (admittedly, while denying wrongdoing) related to the dining hall employees and union efforts. And when the “tragic coincidence” occurred, who did the College opt to bring to handle the investigation? Why, in a tragic coincidence, they selected a law firm that is known for union-busting — one that even brags about it on their web site.

My speculation, based purely upon experiences in other institutions, is that some individual did, in fact, trigger the authorization issue as an anti-union tactic — although, perhaps, without the authorization or approval of the administration. The College’s reaction has had all the hallmarks of an institution “circling the wagons” and doing damage control for ill-advised actions by one member. Yes, the action achieved the desired effect and disrupted the unionization effort, but it also has had (and will continue to have) consequences far beyond the original intent.

Dodie’s letter calls for the community to move on, stop finger-pointing, and begin the healing. I agree, there is an excellent opportunity here. Pomona could demonstrate its commitment to its people, and show that it has been dealing in good faith: with the College’s legal and financial resources, Pomona could promote healing by helping the fired workers obtain whatever authorizations the law requires. Sponsor them for green cards, say, or H2B visas at the very least. No question it would be expensive and time consuming, but such action would go great lengths to disprove the accusations of the College’s detractors. It would show that Pomona is dedicated to doing the right thing.

As a small business owner, I fully understand the importance of controlling costs. But I also know that costs are just one part of the equation, and that a business’ good name and positive reputation are vital to its survival. Pomona is known for being one of the top five liberal arts institutions in the United States. What sets it apart from the many other colleges and universities? Time and again, people cite the small, personal nature of Pomona. The College doesn’t just have outstanding faculty, but has outstanding faculty who truly care about the students. The Administration fosters faculty and provides freedom and opportunities unmatched by other institutions. College is not merely a place for academic growth, but for all forms of personal growth, and Pomona is known to offer an ideal environment for development. This is why students turn down larger institutions like Stanford, Berkeley, or Ivy League Colleges to attend Pomona.

By not extending the nurturing environment to the entire college community, however, Pomona risks losing the bright shine from its reputation. Creating a caste system, where one group is cultivated and another group is repressed is antithetical to the principles upon which Pomona was founded. It may make sense from the perspective of running a for-profit business, but that is not what Pomona represents. Having unionized dining-hall workers would increase Pomona’s cost of doing business. However, this increase in cost is nothing compared to the damage that would be done if people started perceiving the College as just another uncaring corporate institution.

1 Despite this opposition to the workers unionizing, these communications from Pomona have all included the somewhat mysterious statement that the College can’t initiate a unionization vote. It’s an odd statement to make. No one has accused Pomona of failing to initiate a vote. The accusation is that the College is hindering the effort of the workers to get to the point where they can initiate a vote themselves.

Filed in:

Page 10 of 55« First...89101112...2030...Last »