How do I insert additional tokens into a Hibernate Search token stream?









up vote
0
down vote

favorite












In Hibernate Search, how do I add support for full, startsWith and endsWith matching?



E.g., for indexing values




doc 1: bridge
doc 2: bridge rusting
doc 3: strong bridge


I want queries to return:




query: ^bridge$
result: doc 1

query: ^bridge
result: docs 1 & 2

query: bridge$
result: docs 1 & 3


The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:




doc 1: _BEGIN_ bridge _END_
doc 2: _BEGIN_ bridge rusting _END_
doc 3: _BEGIN_ strong bridge _END_


so that:




query: _BEGIN_ bridge _END_
returns: docs 1

query: _BEGIN_ bridge
returns: docs 1 and 2

query: bridge _END_
returns: docs 1 and 3


Conceptually this should work. But how to implement?



Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?










share|improve this question

























    up vote
    0
    down vote

    favorite












    In Hibernate Search, how do I add support for full, startsWith and endsWith matching?



    E.g., for indexing values




    doc 1: bridge
    doc 2: bridge rusting
    doc 3: strong bridge


    I want queries to return:




    query: ^bridge$
    result: doc 1

    query: ^bridge
    result: docs 1 & 2

    query: bridge$
    result: docs 1 & 3


    The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:




    doc 1: _BEGIN_ bridge _END_
    doc 2: _BEGIN_ bridge rusting _END_
    doc 3: _BEGIN_ strong bridge _END_


    so that:




    query: _BEGIN_ bridge _END_
    returns: docs 1

    query: _BEGIN_ bridge
    returns: docs 1 and 2

    query: bridge _END_
    returns: docs 1 and 3


    Conceptually this should work. But how to implement?



    Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      In Hibernate Search, how do I add support for full, startsWith and endsWith matching?



      E.g., for indexing values




      doc 1: bridge
      doc 2: bridge rusting
      doc 3: strong bridge


      I want queries to return:




      query: ^bridge$
      result: doc 1

      query: ^bridge
      result: docs 1 & 2

      query: bridge$
      result: docs 1 & 3


      The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:




      doc 1: _BEGIN_ bridge _END_
      doc 2: _BEGIN_ bridge rusting _END_
      doc 3: _BEGIN_ strong bridge _END_


      so that:




      query: _BEGIN_ bridge _END_
      returns: docs 1

      query: _BEGIN_ bridge
      returns: docs 1 and 2

      query: bridge _END_
      returns: docs 1 and 3


      Conceptually this should work. But how to implement?



      Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?










      share|improve this question













      In Hibernate Search, how do I add support for full, startsWith and endsWith matching?



      E.g., for indexing values




      doc 1: bridge
      doc 2: bridge rusting
      doc 3: strong bridge


      I want queries to return:




      query: ^bridge$
      result: doc 1

      query: ^bridge
      result: docs 1 & 2

      query: bridge$
      result: docs 1 & 3


      The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:




      doc 1: _BEGIN_ bridge _END_
      doc 2: _BEGIN_ bridge rusting _END_
      doc 3: _BEGIN_ strong bridge _END_


      so that:




      query: _BEGIN_ bridge _END_
      returns: docs 1

      query: _BEGIN_ bridge
      returns: docs 1 and 2

      query: bridge _END_
      returns: docs 1 and 3


      Conceptually this should work. But how to implement?



      Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?







      hibernate search lucene






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 18:45









      Dimitri S.

      366




      366



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242261%2fhow-do-i-insert-additional-tokens-into-a-hibernate-search-token-stream%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242261%2fhow-do-i-insert-additional-tokens-into-a-hibernate-search-token-stream%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党