Search Results substring

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nel

    Search Results substring

    Hi all,

    I have been searching for some clues as to how to show a substring from a
    database search.

    $pagetitle = "Page Title";
    $pagetext = "This is <b>a typical</b> string that would be stored<br>in the
    database.";


    Search for "that"

    results would look like

    1. Page Title
    ...string that would...
    2. Another page
    ...computers that can...
    3. Further Page
    ...languages that are...

    At the moment the search results just show the page title. The idea is that
    in the set of results I can show the user the context of each result, a bit
    like a search engine does. Ideall I would like up to 10 words either side
    of the search keyword.

    BTW php+ mysql

    Nel.



  • Erwin Moller

    #2
    Re: Search Results substring

    Nel wrote:
    [color=blue]
    > Hi all,
    >
    > I have been searching for some clues as to how to show a substring from a
    > database search.
    >
    > $pagetitle = "Page Title";
    > $pagetext = "This is <b>a typical</b> string that would be stored<br>in
    > the database.";
    >
    >
    > Search for "that"
    >
    > results would look like
    >
    > 1. Page Title
    > ...string that would...
    > 2. Another page
    > ...computers that can...
    > 3. Further Page
    > ...languages that are...
    >
    > At the moment the search results just show the page title. The idea is
    > that in the set of results I can show the user the context of each result,
    > a bit
    > like a search engine does. Ideall I would like up to 10 words either side
    > of the search keyword.
    >
    > BTW php+ mysql
    >
    > Nel.[/color]


    Hi Nel,

    use LIKE

    SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');

    Because we don't know how your database is designed it is impossible to say
    how the pagetitle should be retrieved.
    I expect you reference a foreign key in tblpagetext on the PK in
    tblpagetitle??

    Anyway, if you have the pagetext in it is easy to get some words around it.
    use explode on space and find the location of the first 'that' and get 5
    before and 5 after (if possible).
    go to www.php.net and browse a little for explode and count and the like.
    I am quite sure somebody handy with regexpressions codes this in 1 line. :-)

    Good luck!

    Regards,
    Erwin Moller


    Comment

    • Nel

      #3
      Re: Search Results substring

      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:412f11a8$0 $48933$e4fe514c @news.xs4all.nl ...[color=blue]
      > Nel wrote:
      >[color=green]
      > > Hi all,
      > >
      > > I have been searching for some clues as to how to show a substring from[/color][/color]
      a[color=blue][color=green]
      > > database search.
      > >
      > > $pagetitle = "Page Title";
      > > $pagetext = "This is <b>a typical</b> string that would be stored<br>in
      > > the database.";
      > >
      > >
      > > Search for "that"
      > >
      > > results would look like
      > >
      > > 1. Page Title
      > > ...string that would...
      > > 2. Another page
      > > ...computers that can...
      > > 3. Further Page
      > > ...languages that are...
      > >
      > > At the moment the search results just show the page title. The idea is
      > > that in the set of results I can show the user the context of each[/color][/color]
      result,[color=blue][color=green]
      > > a bit
      > > like a search engine does. Ideall I would like up to 10 words either[/color][/color]
      side[color=blue][color=green]
      > > of the search keyword.
      > >
      > > BTW php+ mysql
      > >
      > > Nel.[/color]
      >
      >
      > Hi Nel,
      >
      > use LIKE
      >
      > SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');
      >
      > Because we don't know how your database is designed it is impossible to[/color]
      say[color=blue]
      > how the pagetitle should be retrieved.
      > I expect you reference a foreign key in tblpagetext on the PK in
      > tblpagetitle??
      >
      > Anyway, if you have the pagetext in it is easy to get some words around[/color]
      it.[color=blue]
      > use explode on space and find the location of the first 'that' and get 5
      > before and 5 after (if possible).
      > go to www.php.net and browse a little for explode and count and the like.
      > I am quite sure somebody handy with regexpressions codes this in 1 line.[/color]
      :-)[color=blue]
      >
      > Good luck!
      >
      > Regards,
      > Erwin Moller
      >[/color]
      Thanks Erwin. I have no problem with the SQL side, just not expereinced in
      arrays too much.

      If I explode(" ",$pagetext ) this will only give me full words. the search
      string could be part of a word.

      Is there a regex that could just take (up to 40 chars)(searchte rm)(up to 40
      chars)?

      Thanks.

      Nel.


      Comment

      • Nel

        #4
        Re: Search Results substring

        "Nel" <nelly@ne14.co. NOSPAMuk> wrote in message
        news:412f139e$0 $87293$ed2619ec @ptn-nntp-reader01.plus.n et...[color=blue]
        > "Erwin Moller"
        > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
        > message news:412f11a8$0 $48933$e4fe514c @news.xs4all.nl ...[color=green]
        > > Nel wrote:
        > >[color=darkred]
        > > > Hi all,
        > > >
        > > > I have been searching for some clues as to how to show a substring[/color][/color][/color]
        from[color=blue]
        > a[color=green][color=darkred]
        > > > database search.
        > > >
        > > > $pagetitle = "Page Title";
        > > > $pagetext = "This is <b>a typical</b> string that would be[/color][/color][/color]
        stored<br>in[color=blue][color=green][color=darkred]
        > > > the database.";
        > > >
        > > >
        > > > Search for "that"
        > > >
        > > > results would look like
        > > >
        > > > 1. Page Title
        > > > ...string that would...
        > > > 2. Another page
        > > > ...computers that can...
        > > > 3. Further Page
        > > > ...languages that are...
        > > >
        > > > At the moment the search results just show the page title. The idea[/color][/color][/color]
        is[color=blue][color=green][color=darkred]
        > > > that in the set of results I can show the user the context of each[/color][/color]
        > result,[color=green][color=darkred]
        > > > a bit
        > > > like a search engine does. Ideall I would like up to 10 words either[/color][/color]
        > side[color=green][color=darkred]
        > > > of the search keyword.
        > > >
        > > > BTW php+ mysql
        > > >
        > > > Nel.[/color]
        > >
        > >
        > > Hi Nel,
        > >
        > > use LIKE
        > >
        > > SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');
        > >
        > > Because we don't know how your database is designed it is impossible to[/color]
        > say[color=green]
        > > how the pagetitle should be retrieved.
        > > I expect you reference a foreign key in tblpagetext on the PK in
        > > tblpagetitle??
        > >
        > > Anyway, if you have the pagetext in it is easy to get some words around[/color]
        > it.[color=green]
        > > use explode on space and find the location of the first 'that' and get 5
        > > before and 5 after (if possible).
        > > go to www.php.net and browse a little for explode and count and the[/color][/color]
        like.[color=blue][color=green]
        > > I am quite sure somebody handy with regexpressions codes this in 1 line.[/color]
        > :-)[color=green]
        > >
        > > Good luck!
        > >
        > > Regards,
        > > Erwin Moller
        > >[/color]
        > Thanks Erwin. I have no problem with the SQL side, just not expereinced[/color]
        in[color=blue]
        > arrays too much.
        >
        > If I explode(" ",$pagetext ) this will only give me full words. the search
        > string could be part of a word.
        >
        > Is there a regex that could just take (up to 40 chars)(searchte rm)(up to[/color]
        40[color=blue]
        > chars)?
        >
        > Thanks.
        >
        > Nel.
        >[/color]
        I have been messing with
        ..{0,30}[:alnum: ]($search)[:alnum: ].{0,40}

        but this only gives words surrounded by spaces, not part of word or word
        followed by , or .

        HELP!!!!!!!

        Nel.


        Comment

        Working...