Hello,
I have a problem when i search with lucene, but i dont know if this is a
problem of my Index or my Search.
At Index, I have like parameter a list of data of an individual(the list is
with data of my Ontology Individuals)
The list has values like "Name:PeterRooney", "Age:25", "From:NY" if the
individual is a person
but if the individual is an Event it has "Date:20/09/2014" and the is more
types of individuals.
However, the Docs have differente keys for the type of individual , and the
Data is type String.
This is all my code for the index of the data
public class Indexer {
public Indexer() {}
/** Index all text files under a directory. */
public IndexWriter CreateIndexDir(List<String> list) {
String indexPath = "index";
boolean create = true;
try {
Directory dir = FSDirectory.open(new File(indexPath));
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_0,
analyzer);
if (create) {
// Create a new index in the directory, removing any
// previously indexed documents:
iwc.setOpenMode(OpenMode.CREATE);
} else {
// Add new documents to an existing index:
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
}
// Optional: for better indexing performance, if you
// are indexing many documents, increase the RAM
// buffer. But if you do this, increase the max heap
// size to the JVM (eg add -Xmx512m or -Xmx1g):
//
// iwc.setRAMBufferSizeMB(256.0);
IndexWriter writer = new IndexWriter(dir, iwc);
return writer;
} catch (IOException e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
return null;
}
}
public void indexDocs(IndexWriter writer, List<String> listInd)
throws IOException {
try {
Document doc = new Document();
String aux;
int pos;
for(int i=0;i<listInd.size();i++){
aux = listInd.get(i);
pos = aux.indexOf(":");
doc.add(new StringField(aux.substring(0,
pos),aux.substring(pos+1, aux.length()),Field.Store.YES));
}
if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {
writer.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been
indexed) so
// we use updateDocument instead to replace the old one
matching the exact
// path, if present:
// System.out.println("updating " + file);
// writer.updateDocument(new StringBuffer("","",doc);
}
} finally {
// fis.close();
}
}
public void closeWriter(IndexWriter writer) throws IOException{
writer.close();
}
}
When i make the search i have this code:
public class SearchEngine {
// private IndexSearcher searcher = null;
// private QueryParser parser = null;
public SearchEngine(String line) throws IOException, ParseException {
String index = "index";
String field = "Name";
String queries = null;
int repeat = 1;
boolean raw = false;
String queryString = null;
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(
FSDirectory.open(new File(index)));
IndexSearcher searcher = new IndexSearcher(reader);
// :Post-Release-Update-Version.LUCENE_XY:
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0);
QueryParser parser = new QueryParser(Version.LUCENE_4_10_0, field,
analyzer);
Query query = parser.parse(line);
if (repeat > 0) { // repeat & time as
benchmark
Date start = new Date();
for (int i = 0; i < repeat; i++) {
searcher.search(query, null, 100);
}
}
doPagingSearch(searcher, query, hitsPerPage, raw, queries == null &&
queryString == null);
reader.close();
}
public List<String> doPagingSearch(IndexSearcher searcher, Query query,
int hitsPerPage, boolean raw, boolean
interactive) throws IOException {
// Collect enough docs to show 5 pages
TopDocs results = searcher.search(query, 1 * hitsPerPage);
ScoreDoc[] hits = results.scoreDocs;
List<String> result = new ArrayList<String>();
int numTotalHits = results.totalHits;
int start = 0;
int end = Math.min(numTotalHits, hitsPerPage);
while (true) {
end = Math.min(hits.length, start + hitsPerPage);
for (int i = start; i < end; i++) {
if (raw) { // output raw format
continue;
}
Document doc = searcher.doc(hits[i].doc);
String path = doc.get("Name");
result.add(path);
System.out.println(path);
}
if (!interactive || end == 0) {
break;
}
end = Math.min(numTotalHits, start + hitsPerPage);
}
return result;
}
}
I call these object in this form :
Indexer ind = new Indexer();
IndexWriter indW;
for(int i=0;i<listaIndividuos.size();i++){
List<String> listData = ontM.getInfo(listaIndividuos.get(i));
indW = ind.CreateIndexDir(listData);
ind.indexDocs(indW, listData);
ind.closeWriter(indW);
}
SearchEngine sEng = new SearchEngine("PeterRooney");
2014-09-16 5:17 GMT-05:00 atawfik <[email protected]>:
> Hi,
>
> Can you elaborate more on the confusion or doubt you have? Can you provide
> a sample of your document and query that give you the trouble?
>
> I was not able to deduce what is the problem.
>
> Regards
> Ameer
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Doubt-Lucene-tp4159068p4159100.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>