You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ingo Renner <in...@typo3.org> on 2010/08/26 21:07:58 UTC

Cutom filter implementation, advice needed

Hi *,

I implemented a custom filter and am using it through a QParserPlugin. I'm wondering however, whether my implementation is that clever yet...

Here's my QParser; I'm wondering whether I should apply the filter to all documents in the index (I already guess it's a bad idea) or whether I should use the query as provided by the already available query parser, see the parse() method.



	public AccessFilterQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
		super(qstr, localParams, params, req);

		QParserPlugin parserPlugin = req.getCore().getQueryPlugin(QParserPlugin.DEFAULT_QTYPE);
		QParser parser = parserPlugin.createParser(qstr, localParams, params, req);

		try {
			preConstructedQuery = parser.getQuery();
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}

		String fieldName = localParams.get(AccessParams.ACCESS_FIELD, "access");

		this.accessFilter = new AccessFilter(fieldName, qstr);
	}

	@Override
	public Query parse() throws ParseException {

		Query allDocs = new MatchAllDocsQuery();

		// return new FilteredQuery(allDocs, accessFilter);
		return new FilteredQuery(preConstructedQuery, accessFilter);
	}


I'd be happy about any advice...


best
Ingo


-- 
Ingo Renner
TYPO3 Core Developer, Release Manager TYPO3 4.2, Admin Google Summer of Code

TYPO3 Enterprise Content Management System
http://typo3.org

Apache Solr for TYPO3 - Enterprise Search meets Enterprise Content Management
http://www.typo3-solr.com







Re: Cutom filter implementation, advice needed

Posted by Ingo Renner <in...@typo3.org>.
Am 26.08.2010 um 21:07 schrieb Ingo Renner:

Hi again,

> I implemented a custom filter and am using it through a QParserPlugin. I'm wondering however, whether my implementation is that clever yet...
> 
> Here's my QParser; I'm wondering whether I should apply the filter to all documents in the index (I already guess it's a bad idea) or whether I should use the query as provided by the already available query parser, see the parse() method.


No Java experts around? ^^


Ingo

-- 
Ingo Renner
TYPO3 Core Developer, Release Manager TYPO3 4.2, Admin Google Summer of Code

TYPO3 Enterprise Content Management System
http://typo3.org







Re: Cutom filter implementation, advice needed

Posted by Ingo Renner <in...@typo3.org>.
Am 26.08.2010 um 21:07 schrieb Ingo Renner:

For those interested and for "the" Google, I found a working solution myself. The QParser is now down to this:


	public AccessFilterQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
		super(qstr, localParams, params, req);

		this.accessFilter = new AccessFilter(
			localParams.get(AccessParams.ACCESS_FIELD, "access"), 
			qstr
		);
	}

	@Override
	public Query parse() throws ParseException {
		return new ConstantScoreQuery(accessFilter);
	}


Of course the MatchAllDocsQuery was a bad idea and the FilteredQuery added an unwanted side effect to the query: well ... it filtered the search results in addition to any other queries - who would have guessed ;)


All the best, hope it's helpful to someone
Ingo

-- 
Ingo Renner
TYPO3 Core Developer, Release Manager TYPO3 4.2, Admin Google Summer of Code

TYPO3 Enterprise Content Management System
http://typo3.org

Apache Solr for TYPO3 - Enterprise Search meets Enterprise Content Management
http://www.typo3-solr.com