FAQ
Hi All,

I have a search form which has an input area for key search and also three
optional select boxs *Catagory, Department and Year. *
My question is how can I filter the results if users select a category or
a department or a year or a combination of them.

*index *:

IndexWriter indexWriter =
*new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
*new*StandardAnalyzer(),true);

Document document = *new* Document();

document.add(Field.*Text*("text", docText));

document.add(Field.*UnIndexed*("department", depart));

document.add(Field.*UnIndexed*(
"category", courseId));

document.add(Field.*UnIndexed*(
"year", year));

indexWriter.addDocument(document);

indexWriter.close();



*search: *

*Searcher searcher = new IndexSearcher(API.getRootPath() + "/data/LUCENE/");
Analyzer analyzer = new StandardAnalyzer();*

* Query query = QueryParser.parse(request.getParameter("query"), "text",
analyzer);
Hits hits = searcher.search (query);*

I do not konw how implement a filter to the results of the search for
catgory or year or department.

Thanks,

Massoud

Search Discussions

  • Testn at Sep 11, 2007 at 1:34 am
    It's probably easier to add category, department, year as a part of query and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a category or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"), "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the search for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context: http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at Nabble.com.


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • M.K at Sep 11, 2007 at 4:00 pm
    I am not sure, I understant perfectly.
    Is this the way you said:


    document.add(Field.*UnStored*("text", docText));
    document.add(Field.*Text*("category", category));
    document.add(Field.*Text*("department",department));
    document.add(Field.*Text*("year", year));

    *search:*


    String[] fields = { "text", "category","department","year" };

    BooleanQuery bQuery = *new* BooleanQuery();

    *for* (*int* i = 0; i < fields.length; i++) {

    QueryParser parser = *new* QueryParser(fields[i], analyzer);

    Query q = parser.parse(query);

    bQuery.add(q, *false*, *false*); // combine the queries, neither requiring
    or prohibiting matches

    }
    Hits hits = searcher.search(bQuery);


    MK


    On 9/10/07, testn wrote:


    It's probably easier to add category, department, year as a part of query
    and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a category or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"), "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the search for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context:
    http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at Nabble.com.


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Erick Erickson at Sep 11, 2007 at 4:28 pm
    What version of Lucene are you using? I don't think the form
    b.add(query, false, false) is current.

    Be that as it may, I'm not quite sure what you mean by
    filter. If I'm reading your intent correctly, wouldn't requiring
    each non-empty field accomplish what you want? Which would
    be something like
    b.add(query, BooleanClause.MUST);

    Best
    Erick
    On 9/11/07, M. K wrote:

    I am not sure, I understant perfectly.
    Is this the way you said:


    document.add(Field.*UnStored*("text", docText));
    document.add(Field.*Text*("category", category));
    document.add(Field.*Text*("department",department));
    document.add(Field.*Text*("year", year));

    *search:*


    String[] fields = { "text", "category","department","year" };

    BooleanQuery bQuery = *new* BooleanQuery();

    *for* (*int* i = 0; i < fields.length; i++) {

    QueryParser parser = *new* QueryParser(fields[i], analyzer);

    Query q = parser.parse(query);

    bQuery.add(q, *false*, *false*); // combine the queries, neither requiring
    or prohibiting matches

    }
    Hits hits = searcher.search(bQuery);


    MK


    On 9/10/07, testn wrote:


    It's probably easier to add category, department, year as a part of query
    and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a
    category
    or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"),
    "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the search for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context:
    http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at Nabble.com.


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • M.K at Sep 11, 2007 at 4:46 pm
    Lucene 1.4.3

    ignor the filter words.
    My question was:
    I have a search form which has an input area for key search and also three
    optional select boxs *Catagory, Department and Year. *
    How can I implement that? Is it correct the way I wrote in my last email.
    Thanks,
    MK


    On 9/11/07, Erick Erickson wrote:

    What version of Lucene are you using? I don't think the form
    b.add(query, false, false) is current.

    Be that as it may, I'm not quite sure what you mean by
    filter. If I'm reading your intent correctly, wouldn't requiring
    each non-empty field accomplish what you want? Which would
    be something like
    b.add(query, BooleanClause.MUST);

    Best
    Erick
    On 9/11/07, M. K wrote:

    I am not sure, I understant perfectly.
    Is this the way you said:


    document.add(Field.*UnStored*("text", docText));
    document.add(Field.*Text*("category", category));
    document.add(Field.*Text*("department",department));
    document.add(Field.*Text*("year", year));

    *search:*


    String[] fields = { "text", "category","department","year" };

    BooleanQuery bQuery = *new* BooleanQuery();

    *for* (*int* i = 0; i < fields.length; i++) {

    QueryParser parser = *new* QueryParser(fields[i], analyzer);

    Query q = parser.parse(query);

    bQuery.add(q, *false*, *false*); // combine the queries, neither requiring
    or prohibiting matches

    }
    Hits hits = searcher.search(bQuery);


    MK


    On 9/10/07, testn wrote:


    It's probably easier to add category, department, year as a part of query
    and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a
    category
    or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"),
    "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the search
    for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context:
    http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at Nabble.com.


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Erick Erickson at Sep 11, 2007 at 4:52 pm
    Well, it depends upon how you indexed things <G>....

    Your previous post was along the right lines as
    far as I can see though...

    Erick

    Assuming that you have
    On 9/11/07, M. K wrote:

    Lucene 1.4.3

    ignor the filter words.
    My question was:
    I have a search form which has an input area for key search and also three
    optional select boxs *Catagory, Department and Year. *
    How can I implement that? Is it correct the way I wrote in my last email.
    Thanks,
    MK


    On 9/11/07, Erick Erickson wrote:

    What version of Lucene are you using? I don't think the form
    b.add(query, false, false) is current.

    Be that as it may, I'm not quite sure what you mean by
    filter. If I'm reading your intent correctly, wouldn't requiring
    each non-empty field accomplish what you want? Which would
    be something like
    b.add(query, BooleanClause.MUST);

    Best
    Erick
    On 9/11/07, M. K wrote:

    I am not sure, I understant perfectly.
    Is this the way you said:


    document.add(Field.*UnStored*("text", docText));
    document.add(Field.*Text*("category", category));
    document.add(Field.*Text*("department",department));
    document.add(Field.*Text*("year", year));

    *search:*


    String[] fields = { "text", "category","department","year" };

    BooleanQuery bQuery = *new* BooleanQuery();

    *for* (*int* i = 0; i < fields.length; i++) {

    QueryParser parser = *new* QueryParser(fields[i], analyzer);

    Query q = parser.parse(query);

    bQuery.add(q, *false*, *false*); // combine the queries, neither requiring
    or prohibiting matches

    }
    Hits hits = searcher.search(bQuery);


    MK


    On 9/10/07, testn wrote:


    It's probably easier to add category, department, year as a part of query
    and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and
    also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a
    category
    or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"),
    "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the search
    for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context:
    http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at Nabble.com
    .
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • M.K at Sep 11, 2007 at 4:55 pm
    Thanks Erick.
    MK
    On 9/11/07, Erick Erickson wrote:

    Well, it depends upon how you indexed things <G>....

    Your previous post was along the right lines as
    far as I can see though...

    Erick

    Assuming that you have
    On 9/11/07, M. K wrote:

    Lucene 1.4.3

    ignor the filter words.
    My question was:
    I have a search form which has an input area for key search and also three
    optional select boxs *Catagory, Department and Year. *
    How can I implement that? Is it correct the way I wrote in my last email.
    Thanks,
    MK


    On 9/11/07, Erick Erickson wrote:

    What version of Lucene are you using? I don't think the form
    b.add(query, false, false) is current.

    Be that as it may, I'm not quite sure what you mean by
    filter. If I'm reading your intent correctly, wouldn't requiring
    each non-empty field accomplish what you want? Which would
    be something like
    b.add(query, BooleanClause.MUST);

    Best
    Erick
    On 9/11/07, M. K wrote:

    I am not sure, I understant perfectly.
    Is this the way you said:


    document.add(Field.*UnStored*("text", docText));
    document.add(Field.*Text*("category", category));
    document.add(Field.*Text*("department",department));
    document.add(Field.*Text*("year", year));

    *search:*


    String[] fields = { "text", "category","department","year" };

    BooleanQuery bQuery = *new* BooleanQuery();

    *for* (*int* i = 0; i < fields.length; i++) {

    QueryParser parser = *new* QueryParser(fields[i], analyzer);

    Query q = parser.parse(query);

    bQuery.add(q, *false*, *false*); // combine the queries, neither requiring
    or prohibiting matches

    }
    Hits hits = searcher.search(bQuery);


    MK


    On 9/10/07, testn wrote:


    It's probably easier to add category, department, year as a part
    of
    query
    and
    then requery to get the hits you need.

    M.K wrote:
    Hi All,

    I have a search form which has an input area for key search and
    also
    three
    optional select boxs *Catagory, Department and Year. *
    My question is how can I filter the results if users select a
    category
    or
    a department or a year or a combination of them.

    *index *:

    IndexWriter indexWriter =
    *new* IndexWriter(API.*getRootPath*() + "\\data\\LUCENE" ,
    *new*StandardAnalyzer(),true);

    Document document = *new* Document();

    document.add(Field.*Text*("text", docText));

    document.add(Field.*UnIndexed*("department", depart));

    document.add(Field.*UnIndexed*(
    "category", courseId));

    document.add(Field.*UnIndexed*(
    "year", year));

    indexWriter.addDocument(document);

    indexWriter.close();



    *search: *

    *Searcher searcher = new IndexSearcher(API.getRootPath() +
    "/data/LUCENE/");
    Analyzer analyzer = new StandardAnalyzer();*

    * Query query = QueryParser.parse(request.getParameter("query"),
    "text",
    analyzer);
    Hits hits = searcher.search (query);*

    I do not konw how implement a filter to the results of the
    search
    for
    catgory or year or department.

    Thanks,

    Massoud
    --
    View this message in context:
    http://www.nabble.com/Implement-a-filter-to-the-search-results-tf4418068.html#a12606295
    Sent from the Lucene - Java Users mailing list archive at
    Nabble.com
    .
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedSep 10, '07 at 8:03p
activeSep 11, '07 at 4:55p
posts7
users3
websitelucene.apache.org

3 users in discussion

M.K: 4 posts Erick Erickson: 2 posts Testn: 1 post

People

Translate

site design / logo © 2022 Grokbase