Skip to content

Commit

Permalink
Merge pull request apache#669 from DamienFontaine/MaxBasicQueries
Browse files Browse the repository at this point in the history
JENA-1837: MaxBasicQueries
  • Loading branch information
afs authored May 1, 2020
2 parents 5cf538d + a6e7e1f commit c1ba587
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TextIndexConfig {
Analyzer queryAnalyzer;
String queryParser;
boolean multilingualSupport;
int maxBasicQueries;
boolean valueStored;
boolean ignoreIndexErrors;

Expand Down Expand Up @@ -70,6 +71,14 @@ public void setMultilingualSupport(boolean multilingualSupport) {
this.multilingualSupport = multilingualSupport;
}

public int getMaxBasicQueries() {
return maxBasicQueries;
}

public void setMaxBasicQueries(int maxBasicQueries) {
this.maxBasicQueries = maxBasicQueries;
}

public boolean isValueStored() {
return valueStored;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class TextIndexLucene implements TextIndex {
private final FieldType ftTextNotStored ; // used for lang derived fields
private final FieldType ftTextStoredNoIndex ; // used for lang derived fields
private final boolean isMultilingual ;
private final int maxBasicQueries ;
private final boolean ignoreIndexErrors ;

private Map<String, Analyzer> multilingualQueryAnalyzers = new HashMap<>();
Expand All @@ -132,6 +133,8 @@ public TextIndexLucene(Directory directory, TextIndexConfig config) {
this.directory = directory ;
this.docDef = config.getEntDef() ;

this.maxBasicQueries = config.getMaxBasicQueries();

this.isMultilingual = config.isMultilingualSupport();
if (this.isMultilingual && config.getEntDef().getLangField() == null) {
//multilingual index cannot work without lang field
Expand Down Expand Up @@ -416,7 +419,7 @@ private Query parseQuery(String queryString, Analyzer analyzer) throws ParseExce
break;
case "SurroundQueryParser":
try {
query = org.apache.lucene.queryparser.surround.parser.QueryParser.parse(queryString).makeLuceneQueryField(docDef.getPrimaryField(), new BasicQueryFactory());
query = org.apache.lucene.queryparser.surround.parser.QueryParser.parse(queryString).makeLuceneQueryField(docDef.getPrimaryField(), new BasicQueryFactory(this.maxBasicQueries));
} catch(org.apache.lucene.queryparser.surround.parser.ParseException e) {
throw new ParseException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ public TextIndex open(Assembler a, Resource root, Mode mode) {
}
isMultilingualSupport = mlsNode.asLiteral().getBoolean();
}


int maxBasicQueries = 1024;
Statement maxBasicQueriesStatement = root.getProperty(pMaxBasicQueries);
if (null != maxBasicQueriesStatement) {
RDFNode mbqNode = maxBasicQueriesStatement.getObject();
if (! mbqNode.isLiteral()) {
throw new TextIndexException("text:maxBasicQueries property must be a int : " + mbqNode);
}
maxBasicQueries = mbqNode.asLiteral().getInt();
}

// define any property lists for text:query
Statement propListsStmt = root.getProperty(pPropLists);
if (null != propListsStmt) {
Expand Down Expand Up @@ -190,6 +200,7 @@ public TextIndex open(Assembler a, Resource root, Mode mode) {
config.setQueryAnalyzer(queryAnalyzer);
config.setQueryParser(queryParser);
config.setMultilingualSupport(isMultilingualSupport);
config.setMaxBasicQueries(maxBasicQueries);
config.setValueStored(storeValues);
config.setIgnoreIndexErrors(ignoreIndexErrs);
docDef.setCacheQueries(cacheQueries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class TextVocab
public static final Property pLanguage = Vocab.property(NS, "language") ;
public static final Property pDirectory = Vocab.property(NS, "directory") ; // Lucene
public static final Property pMultilingualSupport = Vocab.property(NS, "multilingualSupport") ;
public static final Property pMaxBasicQueries = Vocab.property(NS, "maxBasicQueries") ;
public static final Property pStoreValues = Vocab.property(NS, "storeValues") ;
public static final Property pIgnoreIndexErrors = Vocab.property(NS, "ignoreIndexErrors") ;
public static final Property pQueryAnalyzer = Vocab.property(NS, "queryAnalyzer") ;
Expand Down

0 comments on commit c1ba587

Please sign in to comment.