Results 1 to 4 of 4
  1. #1
    icewall is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Get a token list with search results

    I'm lost in Lucene API

    I find good results with this code :
    Search.TermQuery(my_search_term)

    Now I have the good documents containing the search result.
    But I would like to get a token list and loop each items in the list to do some statements.

    Could you tell me how to do it please ?

  2. #2
    Jayshri is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Get a token list with search results

    Hi,
    See code below to iterate the search documents and get fields of document.

    for(int i=start; i<=stop; i++)
    {
    Document doc = reader.document(docIds[i].doc);
    for (Iterator<Fieldable> iterator = doc.getFields().iterator(); iterator.hasNext();) {
    Field field = (Field) iterator.next();
    String fieldName;
    String fieldValue;
    boolean isStored;
    boolean isIndexed;

    if(field.isStored())
    {
    fieldName = field.name();
    fieldValue = field.stringValue();
    isStored = true;
    }
    if(field.isIndexed())
    {
    isIndexed = true;
    }
    }
    }

  3. #3
    icewall is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Get a token list with search results

    Thank you Jayshri.
    I didn't think to check if a value is stored or indexed.
    Now I only have 2 fields but it will change later so it will be interesting to use it.

    if(field.isStored())
    {
    fieldName = field.name();
    fieldValue = field.stringValue();
    isStored = true;
    }

    I wonder how to split "fieldValue" into a list of terms.
    Example : "Firefox has located your file and is attempting to retrieve it"

    Search term = Firefox
    A list of term : Firefox | has | located | your | file | and | is | attempting | to | retrieve | it
    A stop word list : has | your | and | is | to | it | ...
    A final list of term : Firefox | located | file | attempting | retrieve

    Loop final list
    Let user choose some associated words
    Ex : Firefox + file + retrieve

    The main idea is to use Lucene to suggest associated words (for document tagging systems).

  4. #4
    icewall is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Get a token list with search results

    Thank you Jayshri.

    To check if a value is stored or indexed.
    Now I only have 2 fields but it will change later so it will be interesting to use it.

    if(field.isStored())
    {
    fieldName = field.name();
    fieldValue = field.stringValue();
    isStored = true;
    }

    I wonder how to split "fieldValue" into a list of terms.

    Example : "Firefox has located your file and is attempting to retrieve it"
    Search term = Firefox
    A list of term : Firefox | has | located | your | file | and | is | attempting | to | retrieve | it
    A stop word list : has | your | and | is | to | it | ...
    A final list of term : Firefox | located | file | attempting | retrieve

    Loop final list
    Let user choose some associated words
    Ex : Firefox + file + retrieve

    The main idea is to use Lucene to suggest associated words (for document tagging systems)

Similar Threads

  1. search within website & retrieve next results page
    By FunkyProg in forum New To Java
    Replies: 1
    Last Post: 03-29-2011, 07:11 AM
  2. Java - Displaying Search Results in jsp using STRUTS
    By selvi in forum Web Frameworks
    Replies: 0
    Last Post: 08-12-2010, 07:48 AM
  3. Design search results .jsp
    By maas in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-19-2010, 07:18 AM
  4. Unique Filter on search results
    By selva in forum Lucene
    Replies: 0
    Last Post: 02-17-2009, 07:32 AM
  5. Problem with displaying search results from an array
    By BHCluster in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 03:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •