From: <mrp...@us...> - 2011-03-17 20:55:19
|
Revision: 4312 http://bigdata.svn.sourceforge.net/bigdata/?rev=4312&view=rev Author: mrpersonick Date: 2011-03-17 20:55:10 +0000 (Thu, 17 Mar 2011) Log Message: ----------- added matchAll capability to free text search Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/search/FullTextIndex.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/ITextIndexer.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BD.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestFullTextIndex.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/FreeTextSearchExpander.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSearchQuery.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/RunningQueryCloseableIterator.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/search/FullTextIndex.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/search/FullTextIndex.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/search/FullTextIndex.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -37,6 +37,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.UUID; @@ -901,9 +902,6 @@ } - /* - * FIXME [prefixMatch] has not been implemented yet. - */ public Hiterator search(final String query, final String languageCode, final boolean prefixMatch) { @@ -913,6 +911,7 @@ prefixMatch,// .4, // minCosine 10000, // maxRank + false, // matchAllTerms this.timeout,// TimeUnit.MILLISECONDS// ); @@ -942,7 +941,7 @@ final double minCosine, final int maxRank) { return search(query, languageCode, false/* prefixMatch */, minCosine, - maxRank, this.timeout, TimeUnit.MILLISECONDS); + maxRank, false, this.timeout, TimeUnit.MILLISECONDS); } @@ -990,6 +989,8 @@ * <code>free</code> will be an exact match on <code>free</code> * but a partial match on <code>freedom</code>. When * <code>false</code>, only exact matches will be made. + * @param matchAllTerms + * if true, return only hits that match all search terms * @param timeout * The timeout -or- ZERO (0) for NO timeout (this is equivalent * to using {@link Long#MAX_VALUE}). @@ -1014,7 +1015,8 @@ */ public Hiterator<Hit> search(final String query, final String languageCode, final boolean prefixMatch, final double minCosine, - final int maxRank, long timeout, final TimeUnit unit) { + final int maxRank, final boolean matchAllTerms, + long timeout, final TimeUnit unit) { final long begin = System.currentTimeMillis(); @@ -1039,6 +1041,7 @@ if (log.isInfoEnabled()) log.info("languageCode=[" + languageCode + "], text=[" + query + "], minCosine=" + minCosine + ", maxRank=" + maxRank + + ", matchAllTerms=" + matchAllTerms + ", timeout=" + timeout + ", unit=" + unit); if (timeout == 0L) { @@ -1126,6 +1129,22 @@ } } + + if (matchAllTerms) { + final int nterms = qdata.terms.size(); + + if (log.isInfoEnabled()) + log.info("nterms: " + nterms); + + final Iterator<Map.Entry<Long,Hit>> it = hits.entrySet().iterator(); + while (it.hasNext()) { + final Hit hit = it.next().getValue(); + if (log.isInfoEnabled()) + log.info("hit terms: " + hit.getTermCount()); + if (hit.getTermCount() != nterms) + it.remove(); + } + } // #of hits. final int nhits = hits.size(); @@ -1151,7 +1170,7 @@ if (log.isInfoEnabled()) log.info("Rank ordering "+nhits+" hits by relevance"); - final Hit[] a = hits.values().toArray(new Hit[0]); + final Hit[] a = hits.values().toArray(new Hit[nhits]); Arrays.sort(a); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/ITextIndexer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/ITextIndexer.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/ITextIndexer.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -100,6 +100,8 @@ * The minimum cosine that will be returned. * @param maxRank * The upper bound on the #of hits in the result set. + * @param matchAllTerms + * if true, return only hits that match all search terms * @param timeout * The timeout -or- ZERO (0) for NO timeout (this is equivalent * to using {@link Long#MAX_VALUE}). @@ -110,6 +112,7 @@ */ public Hiterator<A> search(final String query, final String languageCode, final boolean prefixMatch, final double minCosine, - final int maxRank, long timeout, final TimeUnit unit); + final int maxRank, final boolean matchAllTerms, + long timeout, final TimeUnit unit); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BD.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BD.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BD.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -158,7 +158,7 @@ * <p> * <pre> * - * select ?s ?rank + * select ?s * where { * ?s bd:search "scale-out RDF triplestore" . * ?s bd:maxHits "5"^^xsd:int . @@ -174,7 +174,7 @@ * <p> * <pre> * - * select ?s ?matched + * select ?s * where { * ?s bd:search "scale-out RDF triplestore" . * ?s bd:minRelevance "0.5"^^xsd:double . @@ -185,6 +185,22 @@ final URI MIN_RELEVANCE = new URIImpl(SEARCH_NAMESPACE+"minRelevance"); /** + * Magic predicate used to query for free text search metadata. Use + * in conjunction with {@link #SEARCH} as follows: + * <p> + * <pre> + * + * select ?s + * where { + * ?s bd:search "scale-out RDF triplestore" . + * ?s bd:matchAllTerms "true" . + * } + * + * </pre> + */ + final URI MATCH_ALL_TERMS = new URIImpl(SEARCH_NAMESPACE+"matchAllTerms"); + + /** * Sesame has the notion of a "null" graph. Any time you insert a statement * into a quad store and the context position is not specified, it is * actually inserted into this "null" graph. If SPARQL <code>DATASET</code> Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestFullTextIndex.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestFullTextIndex.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestFullTextIndex.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -133,7 +133,9 @@ final Hiterator hitr = store.getLexiconRelation().getSearchEngine() .search(query, languageCode, false/* prefixMatch */, minCosine, - Integer.MAX_VALUE/* maxRank */, 2L/* timeout */, + Integer.MAX_VALUE/* maxRank */, + false/* matchAllTerms */, + 2L/* timeout */, TimeUnit.SECONDS); // assertEquals("#hits", (long) expected.length, itr.size()); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -22,6 +22,7 @@ import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.impl.BooleanLiteralImpl; +import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.Dataset; import org.openrdf.query.QueryEvaluationException; @@ -60,6 +61,7 @@ import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl; import org.openrdf.query.algebra.evaluation.iterator.FilterIterator; import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; +import org.openrdf.query.impl.MapBindingSet; import com.bigdata.bop.BOp; import com.bigdata.bop.BOpUtility; @@ -75,6 +77,7 @@ import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.bindingSet.ListBindingSet; import com.bigdata.bop.constraint.INBinarySearch; import com.bigdata.bop.engine.IRunningQuery; import com.bigdata.bop.engine.QueryEngine; @@ -98,7 +101,6 @@ import com.bigdata.rdf.internal.constraints.RangeBOp; import com.bigdata.rdf.internal.constraints.SPARQLConstraint; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.XSDBooleanIVValueExpression; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.sail.BigdataSail.Options; @@ -133,6 +135,7 @@ import com.bigdata.striterator.Dechunkerator; import com.bigdata.striterator.DistinctFilter; import com.bigdata.striterator.IChunkedOrderedIterator; +import com.bigdata.striterator.ICloseableIterator; /** * Extended to rewrite Sesame {@link TupleExpr}s onto native {@link Rule}s and @@ -662,7 +665,8 @@ final Value p = sp.getPredicateVar().getValue(); if (s == null && p != null && (BD.RELEVANCE.equals(p) || BD.MAX_HITS.equals(p) || - BD.MIN_RELEVANCE.equals(p))) { + BD.MIN_RELEVANCE.equals(p) || + BD.MATCH_ALL_TERMS.equals(p))) { final Var sVar = sp.getSubjectVar(); Set<StatementPattern> metadata = searchMetadata.get(sVar); if (metadata != null) { @@ -887,13 +891,9 @@ } - /* - * FIXME What is [bs]? It is not being used within this context. - */ CloseableIteration<BindingSet, QueryEvaluationException> doEvaluateNatively(final PipelineOp query, final BindingSet bs, final QueryEngine queryEngine, final IVariable[] required -// , final Collection<Filter> sesameFilters ) throws QueryEvaluationException { @@ -901,13 +901,16 @@ try { // Submit query for evaluation. - runningQuery = queryEngine.eval(query); + if (bs != null) + runningQuery = queryEngine.eval(query, toBindingSet(bs)); + else + runningQuery = queryEngine.eval(query); /* * Wrap up the native bigdata query solution iterator as Sesame * compatible iteration with materialized RDF Values. */ - return wrapQuery(runningQuery, required);//, sesameFilters); + return iterator(runningQuery, database, required); } catch (UnsupportedOperatorException t) { if (runningQuery != null) { @@ -928,7 +931,35 @@ } } + + private static IBindingSet toBindingSet(final BindingSet src) { + if (src == null) + throw new IllegalArgumentException(); + + final ListBindingSet bindingSet = new ListBindingSet(); + + final Iterator<Binding> itr = src.iterator(); + + while(itr.hasNext()) { + + final Binding binding = itr.next(); + + final IVariable var = com.bigdata.bop.Var.var(binding.getName()); + + final IV iv = ((BigdataValue) binding.getValue()).getIV(); + + final IConstant val = new Constant<IV>(iv); + + bindingSet.set(var, val); + + } + + return bindingSet; + + } + + /** * Wrap the {@link IRunningQuery#iterator()}, returning a Sesame compatible * iteration which will visit Sesame binding sets having materialized RDF @@ -952,22 +983,62 @@ // De-chunk the IBindingSet[] visited by that iterator. final IChunkedOrderedIterator<IBindingSet> it2 = new ChunkedWrappedIterator<IBindingSet>( - new Dechunkerator<IBindingSet>(it1)); + // Monitor IRunningQuery and cancel if Sesame iterator is closed. + new RunningQueryCloseableIterator<IBindingSet>(runningQuery, + new Dechunkerator<IBindingSet>(it1))); // Materialize IVs as RDF Values. final CloseableIteration<BindingSet, QueryEvaluationException> result = - // Monitor IRunningQuery and cancel if Sesame iterator is closed. - new RunningQueryCloseableIteration<BindingSet, QueryEvaluationException>(runningQuery, // Convert bigdata binding sets to Sesame binding sets. new Bigdata2Sesame2BindingSetIterator<QueryEvaluationException>( // Materialize IVs as RDF Values. new BigdataBindingSetResolverator(database, it2, required).start( - database.getExecutorService()))); + database.getExecutorService())); return result; } + + public static ICloseableIterator<IBindingSet> iterator( + final IRunningQuery runningQuery) { + + // The iterator draining the query solutions. + final IAsynchronousIterator<IBindingSet[]> it1 = + runningQuery.iterator(); + + // Dechunkify the original iterator + final ICloseableIterator<IBindingSet> it2 = + new Dechunkerator<IBindingSet>(it1); + + // Monitor IRunningQuery and cancel if Sesame iterator is closed. + final ICloseableIterator<IBindingSet> it3 = + new RunningQueryCloseableIterator<IBindingSet>(runningQuery, it2); + + return it3; + + } + + public static CloseableIteration<BindingSet, QueryEvaluationException> + iterator(final IRunningQuery runningQuery, final AbstractTripleStore db, + final IVariable[] required) { + final ICloseableIterator<IBindingSet> it1 = iterator(runningQuery); + + // Wrap in an IChunkedOrderedIterator + final IChunkedOrderedIterator<IBindingSet> it2 = + new ChunkedWrappedIterator<IBindingSet>(it1); + + // Materialize IVs as RDF Values. + final CloseableIteration<BindingSet, QueryEvaluationException> it3 = + // Convert bigdata binding sets to Sesame binding sets. + new Bigdata2Sesame2BindingSetIterator<QueryEvaluationException>( + // Materialize IVs as RDF Values. + new BigdataBindingSetResolverator(db, it2, required).start( + db.getExecutorService())); + + return it3; + + } private void attachNamedGraphsFilterToSearches(final SOpTree sopTree) { @@ -1582,6 +1653,7 @@ IVariableOrConstant<IV> relevance = new Constant(DummyIV.INSTANCE); Literal maxHits = null; Literal minRelevance = null; + boolean matchAllTerms = false; for (StatementPattern meta : metadata) { if (!meta.getSubjectVar().equals(subjVar)) { @@ -1608,12 +1680,17 @@ throw new IllegalArgumentException("illegal metadata: " + meta); } minRelevance = (Literal) oVal; + } else if (BD.MATCH_ALL_TERMS.equals(pVal)) { + if (oVal == null || !(oVal instanceof Literal)) { + throw new IllegalArgumentException("illegal metadata: " + meta); + } + matchAllTerms = ((Literal) oVal).booleanValue(); } } final IAccessPathExpander expander = new FreeTextSearchExpander(database, (Literal) objValue, - maxHits, minRelevance); + maxHits, minRelevance, matchAllTerms); // Decide on the correct arity for the predicate. final BOp[] vars = new BOp[] { @@ -1988,8 +2065,11 @@ final Iterator<IHit> itr = (Iterator)database.getLexiconRelation() .getSearchEngine().search(label, languageCode, - false/* prefixMatch */, 0d/* minCosine */, - 10000/* maxRank */, 1000L/* timeout */, + false/* prefixMatch */, + 0d/* minCosine */, + 10000/* maxRank */, + false/* matchAllTerms */, + 0L/* timeout */, TimeUnit.MILLISECONDS); // ensure that named graphs are handled correctly for quads Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/FreeTextSearchExpander.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/FreeTextSearchExpander.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/FreeTextSearchExpander.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -61,19 +61,21 @@ private final Literal query, maxHits, minRelevance; + private final boolean matchAllTerms; + /** Note: volatile for visibility (or use AtomicReference). */ private volatile Set<URI> graphs; public FreeTextSearchExpander(final AbstractTripleStore database, final Literal query) { - this(database, query, null, null); + this(database, query, null, null, false); } public FreeTextSearchExpander(final AbstractTripleStore database, final Literal query, final Literal maxHits, - final Literal minRelevance) { + final Literal minRelevance, final boolean matchAllTerms) { if (database == null) throw new IllegalArgumentException(); @@ -89,6 +91,8 @@ this.minRelevance = minRelevance; + this.matchAllTerms = matchAllTerms; + } public boolean backchain() { @@ -176,7 +180,8 @@ prefixMatch, minRelevance == null ? 0d : minRelevance.doubleValue()/* minCosine */, maxHits == null ? 10000 : maxHits.intValue()+1/* maxRank */, - 1000L/* timeout */, TimeUnit.MILLISECONDS); + matchAllTerms, + 0L/* timeout */, TimeUnit.MILLISECONDS); } return hiterator; Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/RunningQueryCloseableIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/RunningQueryCloseableIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/RunningQueryCloseableIterator.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -0,0 +1,106 @@ +package com.bigdata.rdf.sail; + +import java.util.NoSuchElementException; + +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.engine.IRunningQuery; +import com.bigdata.striterator.ICloseableIterator; + +/** + * Iteration construct wraps an {@link IRunningQuery} with logic to (a) verify + * that the {@link IRunningQuery} has not encountered an error; and (b) to cancel + * the {@link IRunningQuery} when the iteration is {@link #close() closed}. + */ +public class RunningQueryCloseableIterator<E extends IBindingSet> + implements ICloseableIterator<E> { + + private final IRunningQuery runningQuery; + private final ICloseableIterator<E> src; + private boolean checkedFuture = false; + /** + * The next element is buffered so we can always return it if the + * {@link #runningQuery} was not aborted at the time that {@link #hasNext()} + * return <code>true</code>. + */ + private E current = null; + + public RunningQueryCloseableIterator(final IRunningQuery runningQuery, + final ICloseableIterator<E> src) { + + this.runningQuery = runningQuery; + this.src = src; + + } + + public void close() { + runningQuery.cancel(true/* mayInterruptIfRunning */); + src.close(); + } + + public boolean hasNext() { + + if (current != null) { + // Already buffered. + return true; + } + + if (!src.hasNext()) { + // Source is exhausted. + return false; + } + + // buffer the next element. + current = src.next(); + + // test for abnormal completion of the runningQuery. + if (!checkedFuture && runningQuery.isDone()) { + try { + runningQuery.get(); + } catch (InterruptedException e) { + /* + * Interrupted while waiting on the Future (should not happen + * since the Future is already done). + */ + throw new RuntimeException(e); + } catch (Throwable e) { + /* + * Exception thrown by the runningQuery. + */ + if (runningQuery.getCause() != null) { + // abnormal termination - wrap and rethrow. + throw new RuntimeException(e); + } + // otherwise this is normal termination. + } + checkedFuture = true; + } + + // the next element is now buffered. + return true; + + } + + public E next() { + + if (!hasNext()) + throw new NoSuchElementException(); + + final E tmp = current; + + current = null; + + return tmp; + + } + + /** + * Operation is not supported. + */ + public void remove() { + + // Not supported since we are buffering ahead. + throw new UnsupportedOperationException(); + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSearchQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSearchQuery.java 2011-03-17 19:17:15 UTC (rev 4311) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSearchQuery.java 2011-03-17 20:55:10 UTC (rev 4312) @@ -798,6 +798,7 @@ false, // prefixMatch 0d, // minCosine 10000, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -859,6 +860,7 @@ false, // prefixMatch 0d, // minCosine maxHits+1, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -920,6 +922,7 @@ false, // prefixMatch minRelevance, // minCosine 10000, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -985,6 +988,7 @@ false, // prefixMatch minRelevance, // minCosine 10000, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -1052,6 +1056,7 @@ true, // prefixMatch minRelevance, // minCosine 10000, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -1117,6 +1122,7 @@ true, // prefixMatch minRelevance, // minCosine 10000, // maxRank (=maxResults + 1) + false, // matchAllTerms 1000L, // timeout TimeUnit.MILLISECONDS // unit ); @@ -1139,6 +1145,66 @@ } + { // match all terms + + final String searchQuery = "how now brown cow"; + final double minRelevance = 0.0d; + + final String query = + "select ?s ?o " + + "where " + + "{ " + + " ?s <"+RDFS.LABEL+"> ?o . " + + " ?o <"+BD.SEARCH+"> \""+searchQuery+"\" . " + + " ?o <"+BD.MATCH_ALL_TERMS+"> \"true\" . " + + "}"; + + log.info("\n"+query); + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setIncludeInferred(true /* includeInferred */); + TupleQueryResult result = tupleQuery.evaluate(); + + int i = 0; + while (result.hasNext()) { + log.info(i++ + ": " + result.next().toString()); + } +// assertTrue("wrong # of results: " + i, i == 1); + + result = tupleQuery.evaluate(); + + Collection<BindingSet> answer = new LinkedList<BindingSet>(); + + final ITextIndexer search = + sail.getDatabase().getLexiconRelation().getSearchEngine(); + final Hiterator<IHit> hits = + search.search(searchQuery, + null, // languageCode + true, // prefixMatch + minRelevance, // minCosine + 10000, // maxRank (=maxResults + 1) + true, // matchAllTerms + 1000L, // timeout + TimeUnit.MILLISECONDS // unit + ); + + while (hits.hasNext()) { + final IHit hit = hits.next(); + final IV id = new TermId(VTE.LITERAL, hit.getDocId()); + final URI s = uris.get(id); + final Literal o = literals.get(id); + final BindingSet bs = createBindingSet( + new BindingImpl("s", s), + new BindingImpl("o", o)); + log.info(bs); + answer.add(bs); + } + + compare(result, answer); + + } + } finally { cxn.close(); } @@ -1148,4 +1214,61 @@ } + /* + +prefix BIGDATA_QUERY_HINTS: <http://www.bigdata.com/queryHints#com.bigdata.rdf.sail.QueryHints.optimizer=None> +prefix xsd: <http://www.w3.org/2001/XMLSchema#> +select distinct ?target0 +where { + ?obj0 <http://www.bigdata.com/rdf/search#search> "stainless" . + ?target0 ?p0 ?obj0 . + ?obj1 <http://www.bigdata.com/rdf/search#search> "innovations" . + ?target1 ?p1 ?obj1 . + ?obj2 <http://www.bigdata.com/rdf/search#search> "cabin" . + ?target2 ?p2 ?obj2 . + filter(?target0 = ?target1 && ?target1 = ?target2) . +} + + FILTER (?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlock> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockAttribute> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockReference> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADFile> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADTable> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADTitleBlock> || ?category = <http://www.ms2w.com/ontologies/file/Directory> || ?category = <http://www.ms2w.com/ontologies/file/File> || ?category = <http://www.ms2w.com/ontologies/pdffile/PdfAnnotation> || ?category = <http://www.ms2w.com/ontologies/pdffile/PdfFile> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentAssembly> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeBOM> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/Component> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/Configuration> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentDrawing> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeIndented> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypePartsOnly> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeRevision> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxCopiedPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxStandardPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeTopLevelOnly> ) . + +prefix BIGDATA_QUERY_HINTS: <http://www.bigdata.com/queryHints#com.bigdata.rdf.sail.QueryHints.optimizer=None> +prefix xsd: <http://www.w3.org/2001/XMLSchema#> +select distinct ?target +where { + ?obj0 <http://www.bigdata.com/rdf/search#search> "stainless" . + ?obj0 <http://www.bigdata.com/rdf/search#relevance> ?score0 . + ?target ?p0 ?obj0 . + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category0 . + { + ?obj1 <http://www.bigdata.com/rdf/search#search> "innovations" . + ?obj1 <http://www.bigdata.com/rdf/search#relevance> ?score1 . + ?target ?p1 ?obj1 . + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category1 . + } + { + ?obj2 <http://www.bigdata.com/rdf/search#search> "cabin" . + ?obj2 <http://www.bigdata.com/rdf/search#relevance> ?score2 . + ?target ?p2 ?obj2 . + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category2 . + } +} +ORDER BY DESC(?score2) DESC(?score1) DESC(?score0) +LIMIT 10 OFFSET 0 + + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category0 . + + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category1 . + + ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?category2 . + + FILTER (?category0 = ... ) . + FILTER (?category1 = ... ) . + FILTER (?category2 = ... ) . + + FILTER (?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlock> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockAttribute> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockReference> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADFile> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADTable> || ?category = <http://www.ms2w.com/ontologies/autocad/AutoCADTitleBlock> || ?category = <http://www.ms2w.com/ontologies/file/Directory> || ?category = <http://www.ms2w.com/ontologies/file/File> || ?category = <http://www.ms2w.com/ontologies/pdffile/PdfAnnotation> || ?category = <http://www.ms2w.com/ontologies/pdffile/PdfFile> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentAssembly> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeBOM> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/Component> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/Configuration> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentDrawing> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeIndented> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypePartsOnly> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeRevision> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxCopiedPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxStandardPart> || ?category = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeTopLevelOnly> ) . + FILTER (?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlock> || ?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockAttribute> || ?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockReference> || ?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADFile> || ?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADTable> || ?category0 = <http://www.ms2w.com/ontologies/autocad/AutoCADTitleBlock> || ?category0 = <http://www.ms2w.com/ontologies/file/Directory> || ?category0 = <http://www.ms2w.com/ontologies/file/File> || ?category0 = <http://www.ms2w.com/ontologies/pdffile/PdfAnnotation> || ?category0 = <http://www.ms2w.com/ontologies/pdffile/PdfFile> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentAssembly> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeBOM> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/Component> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/Configuration> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentDrawing> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeIndented> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentPart> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypePartsOnly> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeRevision> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxCopiedPart> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxStandardPart> || ?category0 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeTopLevelOnly> ) . + FILTER (?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlock> || ?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockAttribute> || ?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockReference> || ?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADFile> || ?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADTable> || ?category1 = <http://www.ms2w.com/ontologies/autocad/AutoCADTitleBlock> || ?category1 = <http://www.ms2w.com/ontologies/file/Directory> || ?category1 = <http://www.ms2w.com/ontologies/file/File> || ?category1 = <http://www.ms2w.com/ontologies/pdffile/PdfAnnotation> || ?category1 = <http://www.ms2w.com/ontologies/pdffile/PdfFile> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentAssembly> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeBOM> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/Component> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/Configuration> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentDrawing> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeIndented> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentPart> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypePartsOnly> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeRevision> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxCopiedPart> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxStandardPart> || ?category1 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeTopLevelOnly> ) . + FILTER (?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlock> || ?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockAttribute> || ?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADBlockReference> || ?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADFile> || ?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADTable> || ?category2 = <http://www.ms2w.com/ontologies/autocad/AutoCADTitleBlock> || ?category2 = <http://www.ms2w.com/ontologies/file/Directory> || ?category2 = <http://www.ms2w.com/ontologies/file/File> || ?category2 = <http://www.ms2w.com/ontologies/pdffile/PdfAnnotation> || ?category2 = <http://www.ms2w.com/ontologies/pdffile/PdfFile> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentAssembly> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeBOM> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/Component> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/Configuration> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentDrawing> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeIndented> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmDocumentPart> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypePartsOnly> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmTableTypeRevision> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxCopiedPart> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmToolboxStandardPart> || ?category2 = <http://www.ms2w.com/ontologies/solidworks/20091023/swDmBOMTableTypeTopLevelOnly> ) . + */ + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |