changeset 620:89eb02f9827f

add Lucene all_search_terms_must_match()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Jan 2016 17:27:36 -0700
parents cc3a68033179
children fd15da41afca
files lucene/ext/sane-lucene-queryparser.jar lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneIndex.java
diffstat 3 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
Binary file lucene/ext/sane-lucene-queryparser.jar has changed
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Sun Jan 03 02:03:54 2016 -0700
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Mon Jan 04 17:27:36 2016 -0700
@@ -7,6 +7,7 @@
 local SaneQueryParser = require "java:sane.lucene.queryparser.SaneQueryParser"
 local Version = require "java:org.apache.lucene.util.Version"
 local EnglishAnalyzer = require "java:org.apache.lucene.analysis.en.EnglishAnalyzer"
+local BooleanClause = require "java:org.apache.lucene.search.BooleanClause"
 
 
 local M = {}
@@ -43,6 +44,10 @@
 	index.ensure_open = java_index.ensure_open
 	index.next_id = java_index.nextId
 
+	function index.all_search_terms_must_match()
+		java_index.defaultOccur = BooleanClause.Occur.MUST
+	end
+
 	function index.search(query, from, to, sort)
 		local results = {}
 		local function fn(i,doc_fn)
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Sun Jan 03 02:03:54 2016 -0700
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jan 04 17:27:36 2016 -0700
@@ -49,6 +49,7 @@
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.BooleanClause;
 import sane.lucene.queryparser.SaneQueryParser;
 import sane.lucene.queryparser.FieldParser;
 import sane.lucene.queryparser.MultiFieldParser;
@@ -84,6 +85,7 @@
 	private boolean isClosed = false;
 	private final MultiFieldParser mfp;
 	public final LuanTable indexed_only_fields = new LuanTable();
+	public BooleanClause.Occur defaultOccur = BooleanClause.Occur.SHOULD;
 
 	public LuceneIndex(LuanState luan,String indexDirStr,FieldParser defaultFieldParser,String[] defaultFields) throws LuanException, IOException {
 		mfp = defaultFieldParser==null ? new MultiFieldParser() : new MultiFieldParser(defaultFieldParser,defaultFields);
@@ -130,7 +132,7 @@
 	}
 
 	public void delete(LuanState luan,String queryStr) throws LuanException, IOException, ParseException {
-		Query query = SaneQueryParser.parseQuery(mfp,queryStr);
+		Query query = SaneQueryParser.parseQuery(mfp,queryStr,defaultOccur);
 
 		boolean commit = !writeLock.isHeldByCurrentThread();
 		writeLock.lock();
@@ -344,7 +346,7 @@
 
 	public int advanced_search( final LuanState luan, String queryStr, LuanFunction fn, Integer n, String sortStr ) throws LuanException, IOException, ParseException {
 		Utils.checkNotNull(luan,queryStr);
-		Query query = SaneQueryParser.parseQuery(mfp,queryStr);
+		Query query = SaneQueryParser.parseQuery(mfp,queryStr,defaultOccur);
 		IndexSearcher searcher = threadLocalSearcher.get();
 		boolean inTransaction = searcher != null;
 		if( !inTransaction )