use of org.apache.lucene.search.ConstantScoreQuery in project lucene-solr by apache.
the class EnumField method getRangeQuery.
/**
* {@inheritDoc}
*/
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) {
Integer minValue = stringValueToIntValue(min);
Integer maxValue = stringValueToIntValue(max);
if (field.multiValued() && field.hasDocValues() && !field.indexed()) {
// for the multi-valued dv-case, the default rangeimpl over toInternal is correct
return super.getRangeQuery(parser, field, minValue.toString(), maxValue.toString(), minInclusive, maxInclusive);
}
Query query = null;
final boolean matchOnly = field.hasDocValues() && !field.indexed();
if (matchOnly) {
long lowerValue = Long.MIN_VALUE;
long upperValue = Long.MAX_VALUE;
if (minValue != null) {
lowerValue = minValue.longValue();
if (minInclusive == false) {
++lowerValue;
}
}
if (maxValue != null) {
upperValue = maxValue.longValue();
if (maxInclusive == false) {
--upperValue;
}
}
query = new ConstantScoreQuery(NumericDocValuesField.newRangeQuery(field.getName(), lowerValue, upperValue));
} else {
query = LegacyNumericRangeQuery.newIntRange(field.getName(), DEFAULT_PRECISION_STEP, min == null ? null : minValue, max == null ? null : maxValue, minInclusive, maxInclusive);
}
return query;
}
use of org.apache.lucene.search.ConstantScoreQuery in project lucene-solr by apache.
the class TestSolrQueryParser method testCSQ.
@Test
public void testCSQ() throws Exception {
SolrQueryRequest req = req();
QParser qParser = QParser.getParser("text:x^=3", req);
Query q = qParser.getQuery();
assertTrue(q instanceof BoostQuery);
assertTrue(((BoostQuery) q).getQuery() instanceof ConstantScoreQuery);
assertEquals(3.0, ((BoostQuery) q).getBoost(), 0.0f);
qParser = QParser.getParser("(text:x text:y)^=-3", req);
q = qParser.getQuery();
assertTrue(q instanceof BoostQuery);
assertTrue(((BoostQuery) q).getQuery() instanceof ConstantScoreQuery);
assertEquals(-3.0, ((BoostQuery) q).getBoost(), 0.0f);
req.close();
}
use of org.apache.lucene.search.ConstantScoreQuery in project greplin-lucene-utils by Cue.
the class PredicateBonusQueryTest method testBasics.
@Test
public void testBasics() throws Exception {
IndexWriter writer = new IndexWriter(this.directory, new IndexWriterConfig(Version.LUCENE_35, new WhitespaceAnalyzer(Version.LUCENE_35)));
writer.addDocument(new DocumentBuilder().add("value", "5").build());
writer.close();
IndexReader reader = IndexReader.open(this.directory);
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new ConstantScoreQuery(new TermQuery(new Term("value", "5")));
Assert.assertEquals(1.0, searcher.search(query, 1).getMaxScore(), 0.00001);
Query noBonus = new PredicateBonusQuery(query, Predicates.NONE, 10.0f);
Assert.assertEquals(1.0, searcher.search(noBonus, 1).getMaxScore(), 0.00001);
Query bonus = new PredicateBonusQuery(query, Predicates.ALL, 100.0f);
Assert.assertEquals(101.0, searcher.search(bonus, 1).getMaxScore(), 0.00001);
Query noMatch = new TermQuery(new Term("value", "not5"));
Assert.assertEquals(Double.NaN, searcher.search(noMatch, 1).getMaxScore(), 0.00001);
Query noMatchNoBonus = new PredicateBonusQuery(noMatch, Predicates.NONE, 10.0f);
Assert.assertEquals(Double.NaN, searcher.search(noMatchNoBonus, 1).getMaxScore(), 0.00001);
Query noMatchIgnoresBonus = new PredicateBonusQuery(noMatch, Predicates.ALL, 100.0f);
Assert.assertEquals(Double.NaN, searcher.search(noMatchIgnoresBonus, 1).getMaxScore(), 0.00001);
}
use of org.apache.lucene.search.ConstantScoreQuery in project SearchServices by Alfresco.
the class MinHashFilterTest method buildQuery.
private Query buildQuery(String field, String query, int min, int hashCount, int hashSetSize) throws IOException {
TokenizerChain chain = createMinHashAnalyzer(min, hashCount, hashSetSize);
ArrayList<String> tokens = getTokens(chain, field, query);
chain.close();
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (String token : tokens) {
builder.add(new ConstantScoreQuery(new TermQuery(new Term("text", token))), Occur.SHOULD);
}
builder.setDisableCoord(true);
return builder.build();
}
use of org.apache.lucene.search.ConstantScoreQuery in project SearchServices by Alfresco.
the class SolrAuthoritySetQuery method createWeight.
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
if (!(searcher instanceof SolrIndexSearcher)) {
throw new IllegalStateException("Must have a SolrIndexSearcher");
}
String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
SolrIndexSearcher solrIndexSearcher = (SolrIndexSearcher) searcher;
Properties p = solrIndexSearcher.getSchema().getResourceLoader().getCoreProperties();
boolean doPermissionChecks = Boolean.parseBoolean(p.getProperty("alfresco.doPermissionChecks", "true"));
boolean hasGlobalRead = false;
final HashSet<String> globalReaders = GlobalReaders.getReaders();
for (String auth : auths) {
if (globalReaders.contains(auth)) {
hasGlobalRead = true;
break;
}
}
if (hasGlobalRead || (doPermissionChecks == false)) {
return new MatchAllDocsQuery().createWeight(searcher, needsScores);
}
BitsFilter readFilter = getACLFilter(auths, QueryConstants.FIELD_READER, solrIndexSearcher);
BitsFilter ownerFilter = getOwnerFilter(auths, solrIndexSearcher);
if (globalReaders.contains(PermissionService.OWNER_AUTHORITY)) {
readFilter.or(ownerFilter);
return new ConstantScoreQuery(readFilter).createWeight(searcher, needsScores);
} else {
String[] ownerAuth = { PermissionService.OWNER_AUTHORITY };
BitsFilter ownerReadFilter = getACLFilter(ownerAuth, QueryConstants.FIELD_READER, solrIndexSearcher);
ownerReadFilter.and(ownerFilter);
readFilter.or(ownerReadFilter);
return new ConstantScoreQuery(readFilter).createWeight(searcher, needsScores);
}
}
Aggregations