From 801510074d82116159f9567086925f80b276d290 Mon Sep 17 00:00:00 2001 From: maggiolo00 Date: Wed, 3 Sep 2014 13:06:42 +0200 Subject: [PATCH] fixed #17 --- .../orientechnologies/lucene/OLuceneIndexType.java | 10 +++++++--- .../lucene/manager/OLuceneFullTextIndexManager.java | 12 +++++++----- .../com/orientechnologies/test/TestEmbedded.java | 7 +++++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/test/java/com/orientechnologies/test/TestEmbedded.java diff --git a/src/main/java/com/orientechnologies/lucene/OLuceneIndexType.java b/src/main/java/com/orientechnologies/lucene/OLuceneIndexType.java index 988e5244e93..541862b11ed 100644 --- a/src/main/java/com/orientechnologies/lucene/OLuceneIndexType.java +++ b/src/main/java/com/orientechnologies/lucene/OLuceneIndexType.java @@ -100,10 +100,14 @@ public static Query createQueryId(OIdentifiable value) { return new TermQuery(new Term(OLuceneIndexManagerAbstract.RID, value.toString())); } - public static Query createFullQuery(OIndexDefinition index, OCompositeKey key, Analyzer analyzer, Version version) - throws ParseException { + public static Query createFullQuery(OIndexDefinition index, Object key, Analyzer analyzer, Version version) throws ParseException { - String query = key.getKeys().get(0).toString(); + String query = ""; + if (key instanceof OCompositeKey) { + query = ((OCompositeKey) key).getKeys().get(0).toString(); + } else { + query = key.toString(); + } return getQueryParser(index, query, analyzer, version); diff --git a/src/main/java/com/orientechnologies/lucene/manager/OLuceneFullTextIndexManager.java b/src/main/java/com/orientechnologies/lucene/manager/OLuceneFullTextIndexManager.java index 35784a276d1..55c2d0201bd 100644 --- a/src/main/java/com/orientechnologies/lucene/manager/OLuceneFullTextIndexManager.java +++ b/src/main/java/com/orientechnologies/lucene/manager/OLuceneFullTextIndexManager.java @@ -104,8 +104,7 @@ public Object get(Object key) { Query q = null; try { - q = OLuceneIndexType.createFullQuery(index, (OCompositeKey) key, mgrWriter.getIndexWriter().getAnalyzer(), - getVersion(metadata)); + q = OLuceneIndexType.createFullQuery(index, key, mgrWriter.getIndexWriter().getAnalyzer(), getVersion(metadata)); OCommandContext context = null; if (key instanceof OFullTextCompositeKey) { context = ((OFullTextCompositeKey) key).getContext(); @@ -145,15 +144,18 @@ private Set getResults(Query query, OCommandContext context) { try { IndexSearcher searcher = getSearcher(); - Integer limit = (Integer) context.getVariable("$limit"); -// Map scores = new HashMap(); + Integer limit = null; + if (context != null) { + limit = (Integer) context.getVariable("$limit"); + } + // Map scores = new HashMap(); TopDocs docs = searcher.search(query, (limit != null && limit > 0) ? limit : Integer.MAX_VALUE); ScoreDoc[] hits = docs.scoreDocs; for (ScoreDoc score : hits) { Document ret = searcher.doc(score.doc); String rId = ret.get(RID); results.add(new ORecordId(rId)); -// scores.put(rId, score.score); + // scores.put(rId, score.score); } // if (context != null) { // context.setVariable("$luceneScore", scores); diff --git a/src/test/java/com/orientechnologies/test/TestEmbedded.java b/src/test/java/com/orientechnologies/test/TestEmbedded.java new file mode 100644 index 00000000000..1e1b5d2d40b --- /dev/null +++ b/src/test/java/com/orientechnologies/test/TestEmbedded.java @@ -0,0 +1,7 @@ +package com.orientechnologies.test; + +/** + * Created by enricorisa on 03/09/14. + */ +public class TestEmbedded { +}