solr-vector-scoring icon indicating copy to clipboard operation
solr-vector-scoring copied to clipboard

Solr 7 createWeight Exception

Open rikkuporta opened this issue 6 years ago • 3 comments

When following your installation procedure and executing your Examples, I ran into the following error with Query 1:

java.lang.UnsupportedOperationException: Query {! type=vp f=vector vector=0.1,4.75,0.3,1.2,0.7,4.0 v=} does not implement createWeight

rikkuporta avatar Mar 20 '18 13:03 rikkuporta

Even i'm facing the same issue

trace":"java.lang.UnsupportedOperationException: Query {! type=vp f=vector vector=0.1,4.75,0.3,1.2,0.7,4.0 cosine=false v=} does not implement createWeight\n\tat org.apache.lucene.search.Query.createWeight(Query.java:66)\n\tat org.apache.lucene.queries.CustomScoreQuery$CustomWeight.(CustomScoreQuery.java:198)\n\tat org.apache.lucene.queries.CustomScoreQuery.createWeight(CustomScoreQuery.java:313)\n\tat org.apache.lucene.search.IndexSearcher.createWeight(IndexSearcher.java:743)\n\tat org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:463)\n\tat org.apache.solr.search.SolrIndexSearcher.buildAndRunCollectorChain(SolrIndexSearcher.java:217)\n\tat org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1622)\n\tat org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1439)\n\tat org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:586)\n\tat org.apache.solr.handler.component.QueryComponent.doProcessUngroupedSearch(QueryComponent.java:1435)\n\tat org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:375)\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:298)\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:199)\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2539)\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:709)\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:515)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:377)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:323)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:531)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)\n\tat java.lang.Thread.run(Thread.java:748)\n", "code":500}}

jagadish20 avatar Dec 04 '18 11:12 jagadish20

this plugin was developed for 6.6.0 as mentioned in the description. this won't work with 7.x because overridden method createWeight has changed in 7.x.If you wish to use this 7.x just replace createVectorQuery.java with the following code and create a jar.

package com.github.saaay71.solr;
import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
public class VectorQuery extends Query {
	String queryStr = "";
	Query q;
	public VectorQuery(Query subQuery) {
		this.q = subQuery;
	}
	
	public void setQueryString(String queryString){
		this.queryStr = queryString;
	}

	@Override
	public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
		Weight w;
		if(q == null){
			w =  new ConstantScoreWeight(this, boost) {
				@Override
				public Scorer scorer(LeafReaderContext context) throws IOException {
					return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc()));
				}

				@Override
				public boolean isCacheable(LeafReaderContext ctx) {
					// TODO Auto-generated method stub
					return false;
				}
			};
		}else{
			w = searcher.createWeight(q, needsScores, boost);
		}
		return w;
	}

	@Override
	public String toString(String field) {
		return queryStr;
	}

	@Override
	public boolean equals(Object other) {
		return sameClassAs(other) &&
				queryStr.equals(other.toString());
	}

	@Override
	public int hashCode() {
		return classHash() ^ queryStr.hashCode();
	}

}

shaggyy28 avatar Jan 17 '19 05:01 shaggyy28

I am getting the same error while trying on 8.6. I updated the VectorQuery class with the above code but still, the error persists. Anybody solved this on 8.6?

satishsilveri avatar Oct 07 '20 18:10 satishsilveri