Lucene Query

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Lucene Query

Lee Li Bin
Hi,

 

The following query, I am getting only the file path results. I have a field
name 'text' in the index. May I know do I display the text file data?

Is this the problem with the indexing or the query string?

 

Creating Index:

Document doc5 = new Document();

doc5.add(Field.UnIndexed("path", path));

doc5.add(Field.Text("MMmanualType", new StringReader(manualType)));

doc5.add(Field.Text("text", new StringReader(info)));

 

 

Search:

TermQuery queryOM = new TermQuery(new Term("text",OMcriteriaIn));

subquery.add(new BooleanClause(query3, true, false));

subquery.add(new BooleanClause(queryOM, true, false));

System.out.println("Searching for: " + subquery.toString("text"));

Hits hits = searcher.search(subquery);

System.out.println("Number of matching documents = " + hits.length());

 

for (int c = 0; c < hits.length(); c++) {

Document doc = hits.doc(c);

System.out.println("Query found in file: " + doc.get("path"));

System.out.println("Content: " + doc.get("text"));

 


}

 

 

Regards,

Lee Li Bin

 

Reply | Threaded
Open this post in threaded view
|

Re: Lucene Query

Erick Erickson
The problem with your code snippets are that they aren't plain Lucene
API calls. I'm assuming that you've got your own classes that
actually compile  <G>. There's nothing I can say about "what's
going on" without knowing what your custom classes are doing.....

We need to know what analyzers you are using, both at query and
compile time. I suspect that you're using an analyzer that perhaps
breaks on the path separators, but I can't be sure.

I recommend that you try a basic case using the stock Lucene
API code, and post that. Otherwise we're pretty helpless.

Two other things:
1> get a copy of Luke (google lucene luke) and examine your index.
    Luke can also be used to examine the effects of various analyzers
    on queries.
2> use query.toString() to examine what the query looks like after parsing
    and print that to system.out.

Best
Erick

On 6/18/07, Lee Li Bin <[hidden email]> wrote:

>
> Hi,
>
>
>
> The following query, I am getting only the file path results. I have a
> field
> name 'text' in the index. May I know do I display the text file data?
>
> Is this the problem with the indexing or the query string?
>
>
>
> Creating Index:
>
> Document doc5 = new Document();
>
> doc5.add(Field.UnIndexed("path", path));
>
> doc5.add(Field.Text("MMmanualType", new StringReader(manualType)));
>
> doc5.add(Field.Text("text", new StringReader(info)));
>
>
>
>
>
> Search:
>
> TermQuery queryOM = new TermQuery(new Term("text",OMcriteriaIn));
>
> subquery.add(new BooleanClause(query3, true, false));
>
> subquery.add(new BooleanClause(queryOM, true, false));
>
> System.out.println("Searching for: " + subquery.toString("text"));
>
> Hits hits = searcher.search(subquery);
>
> System.out.println("Number of matching documents = " + hits.length());
>
>
>
> for (int c = 0; c < hits.length(); c++) {
>
> Document doc = hits.doc(c);
>
> System.out.println("Query found in file: " + doc.get("path"));
>
> System.out.println("Content: " + doc.get("text"));
>
>
>
>
> }
>
>
>
>
>
> Regards,
>
> Lee Li Bin
>
>
>
>