Revision: 14554
http://gate.svn.sourceforge.net/gate/?rev=14554&view=rev
Author: valyt
Date: 2011-11-15 16:16:00 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
Started work on supporting ranking.
Modified Paths:
--------------
mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractIntersectionQueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractOverlapQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractQueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AndQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/GapQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/OrQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/QueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/RepeatsQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/SequenceQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
Property Changed:
----------------
mimir/trunk/mimir-core/src/
Property changes on: mimir/trunk/mimir-core/src
___________________________________________________________________
Added: svn:mergeinfo
+ /mimir/branches/4.x/mimir-core/src:14299-14316
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -140,6 +140,7 @@
*/
protected static final long MAX_IN_MEMORY_INDEX = 64 * 1024 * 1024;
+
/**
* The top level directory of the Mimir index.
*/
@@ -172,6 +173,11 @@
protected Executor executor;
/**
+ * How many documents get ranked in the first instance.
+ */
+ private int rankedDocumentsCount = 1000;
+
+ /**
* A list of currently active QueryRunners. This is used to close all active
* runners when the query engine itself is closed (thus releasing all open
* files).
@@ -206,6 +212,20 @@
}
/**
+ * Gets the configuration parameter specifying the number of documents that
+ * get ranked in the first instance. This is used to optimise the search
+ * process by limiting the nuber of results that get calculated by default.
+ * @return
+ */
+ public int getRankedDocumentsCount() {
+ return rankedDocumentsCount;
+ }
+
+ public void setRankedDocumentsCount(int rankedDocumentsCount) {
+ this.rankedDocumentsCount = rankedDocumentsCount;
+ }
+
+ /**
* Gets the executor used by this query engine.
*
* @return an executor that can be used for running tasks pertinent to this
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -18,6 +18,8 @@
import gate.mimir.index.IndexException;
import gate.mimir.search.query.Binding;
import gate.mimir.search.query.QueryExecutor;
+import gate.mimir.search.query.QueryNode;
+import gate.mimir.search.score.MimirScorer;
import java.io.IOException;
import java.io.Serializable;
@@ -57,6 +59,10 @@
long startTime = System.currentTimeMillis();
if(currentDocStats == null){
//this is the first search stage
+ // if we're ranking, we need to do multiple passes
+ if(scorer != null) {
+
+ }
currentDocStats = new int[]{nextNonDeleted(), 0};
}
int hitsThisStage = 0;
@@ -116,6 +122,8 @@
}
return nextDocId;
}
+
+
}
protected Thread runningThread;
@@ -142,7 +150,13 @@
protected int timeout = DEFAULT_TIMEOUT;
protected QueryExecutor queryExecutor;
-
+
+ /**
+ * The scorer to be used for ranking the results. Set to <code>null</code> if
+ * ranking is not required.
+ */
+ protected MimirScorer scorer;
+
protected Logger logger = Logger.getLogger(QueryRunnerImpl.class);
/**
@@ -160,6 +174,17 @@
*/
protected boolean closed = false;
+ /**
+ * Creates a query runner in ranking mode.
+ * @param qNode the {@link QueryNode} for the query being executed.
+ * @param scorer the {@link MimirScorer} to use for ranking.
+ * @param qEngine the {@link QueryEngine} used for executing the queries.
+ * @throws IOException
+ */
+ public QueryRunnerImpl(QueryExecutor executor, MimirScorer scorer) {
+ this(executor);
+ this.scorer = scorer;
+ }
public QueryRunnerImpl(QueryExecutor executor) {
this.queryExecutor = executor;
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractIntersectionQueryExecutor.java
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractIntersectionQueryExecutor.java
2011-11-15 16:15:05 UTC (rev 14553)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractIntersectionQueryExecutor.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -37,15 +37,15 @@
* Constructor from {@link QueryEngine}.
* @throws IOException if the index files cannot be accessed.
*/
- public AbstractIntersectionQueryExecutor(QueryEngine engine,
- QueryNode... nodes) throws IOException {
- super(engine);
- this.nodes = nodes;
+ public AbstractIntersectionQueryExecutor(QueryEngine engine, QueryNode query,
+ QueryNode... subNodes) throws IOException {
+ super(engine, query);
+ this.nodes = subNodes;
// prepare all the executors
- this.executors = new QueryExecutor[nodes.length];
+ this.executors = new QueryExecutor[subNodes.length];
this.nextDocIDs = new int[executors.length];
- for(int i = 0; i < nodes.length; i++) {
- executors[i] = nodes[i].getQueryExecutor(engine);
+ for(int i = 0; i < subNodes.length; i++) {
+ executors[i] = subNodes[i].getQueryExecutor(engine);
nextDocIDs[i] = executors[i].nextDocument(-1);
if(nextDocIDs[i] < 0) {
// no results!
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractOverlapQuery.java
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractOverlapQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractOverlapQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -57,7 +57,7 @@
*/
public OverlapQueryExecutor(AbstractOverlapQuery query, QueryEngine
engine,
SubQuery target) throws IOException {
- super(engine);
+ super(engine, query);
this.targetQuery = target;
this.query = query;
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractQueryExecutor.java
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractQueryExecutor.java
2011-11-15 16:15:05 UTC (rev 14553)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/query/AbstractQueryExecutor.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -47,9 +47,15 @@
*/
protected QueryEngine engine;
+ /**
+ * The {@link QueryNode} for the query being executed.
+ */
+ protected QueryNode queryNode;
- protected AbstractQueryExecutor(QueryEngine engine){
+
+ protected AbstractQueryExecutor(QueryEngine engine, QueryNode qNode){
this.engine = engine;
+ this.queryNode = qNode;
latestDocument = -2;
}
@@ -71,6 +77,12 @@
return engine;
}
+
+ @Override
+ public QueryNode getQueryNode() {
+ return queryNode;
+ }
+
// Implementation for the MG4J DocumentIterator interface (only used for
ranking)
@Override
public IntervalIterator intervalIterator() throws IOException {
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/AndQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/AndQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/AndQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -45,7 +45,7 @@
*/
public AndQueryExecutor(AndQuery query, QueryEngine engine)
throws IOException {
- super(engine, query.nodes);
+ super(engine, query, query.nodes);
this.query = query;
}
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -52,7 +52,7 @@
* @param query
*/
public AnnotationQueryExecutor(AnnotationQuery query, QueryEngine engine)
throws IOException {
- super(engine);
+ super(engine, query);
this.query = query;
buildQuery();
}
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/GapQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/GapQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/GapQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -51,7 +51,7 @@
* @throws IOException
*/
public GapQueryExecutor(GapQuery queryNode, QueryEngine engine) throws
IOException {
- super(engine);
+ super(engine, queryNode);
this.gapQuery = queryNode;
wrappedExecutor = queryNode.getWrappedQuery().getQueryExecutor(engine);
}
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/OrQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/OrQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/OrQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -52,7 +52,7 @@
* @throws IOException
*/
public OrQueryExecutor(OrQuery query, QueryEngine engine) throws
IOException {
- super(engine);
+ super(engine, query);
this.query = query;
//prepare all the executors
this.executors = new ExecutorsList(engine, query.getNodes());
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/QueryExecutor.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/QueryExecutor.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/QueryExecutor.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -81,4 +81,10 @@
* @return
*/
public QueryEngine getQueryEngine();
+
+ /**
+ * Gets that {@link QueryNode} representing the query being executed.
+ * @return
+ */
+ public QueryNode getQueryNode();
}
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/RepeatsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/RepeatsQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/RepeatsQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -47,7 +47,7 @@
* @throws IOException
*/
public RepeatsQueryExecutor(RepeatsQuery query, QueryEngine engine) throws
IOException {
- super(engine);
+ super(engine, query);
this.query = query;
this.wrappedExecutor = query.wrappedQuery.getQueryExecutor(engine);
hitsOnCurrentDocument = new LinkedList<Binding[]>();
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/SequenceQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/SequenceQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/SequenceQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -93,7 +93,7 @@
*/
public SequenceQueryExecutor(SequenceQuery query, QueryEngine engine)
throws IOException {
- super(engine, query.nodes);
+ super(engine, query, query.nodes);
this.query = query;
//initialise the internal data
hitsOnCurrentDocument = new LinkedList<Binding[]>();
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/TermQuery.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -119,7 +119,7 @@
* @throws IOException if the index files cannot be accessed.
*/
public TermQueryExecutor(TermQuery node, QueryEngine engine) throws
IOException {
- super(engine);
+ super(engine, node);
this.query = node;
switch(this.query.indexType){
case TOKENS:
Modified:
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
2011-11-15 16:15:05 UTC (rev 14553)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -23,7 +23,10 @@
import java.io.IOException;
-
+/**
+ * Implementation of {@link MimirScorer} that delegates the scoring work to an
+ * MG4J {@link DelegatingScorer}.
+ */
public class DelegatingScoringQueryExecutor implements MimirScorer {
public DelegatingScoringQueryExecutor(DelegatingScorer scorer)
@@ -43,15 +46,11 @@
public Binding nextHit() throws IOException {
return underlyingExecutor.nextHit();
}
-
-
-
public double score() throws IOException {
return underlyingScorer.score();
}
-
private DelegatingScorer underlyingScorer;
private QueryExecutor underlyingExecutor;
Modified: mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
2011-11-15 16:15:05 UTC (rev 14553)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
2011-11-15 16:16:00 UTC (rev 14554)
@@ -21,12 +21,19 @@
import java.io.IOException;
+/**
+ * Base interface for scorers in MÃmir.
+ */
public interface MimirScorer extends DelegatingScorer {
+
public abstract Binding nextHit() throws IOException;
/**
- * The DocumentIterator provided <b>must</b> be a {@link QueryExecutor}.
+ * Wraps a {@link QueryExecutor} allowing this scorer to provide scoring
+ * functionality on top of it. The parameter provided is declared as a
+ * {@link DocumentIterator} to satisfy the extended interface, but the
+ * value provided <b>must</b> be a {@link QueryExecutor}.
*/
@Override
public void wrap(DocumentIterator queryExecutor) throws IOException;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs